gerardocrisci Posted February 1, 2018 Share Posted February 1, 2018 How can I create an api rest (GET POST and authentication) service in an unigui project? thank you Quote Link to comment Share on other sites More sharing options...
hmdsadeghian Posted September 3, 2018 Share Posted September 3, 2018 Hi , I have this question too. Quote Link to comment Share on other sites More sharing options...
Ron Posted September 3, 2018 Share Posted September 3, 2018 You should be able to add an IdHttpServer in the UniServerModule, and process the http requests that way, but on a different port than the server application of course. This demands that the application is loaded, which will not happen until the first mainmodule request is made, as far as I have experienced. Quote Link to comment Share on other sites More sharing options...
GerhardV Posted September 3, 2018 Share Posted September 3, 2018 As delphidude suggested. But you can also use the OnHTTPCommand event on the ServerModule. Just be aware that this is not associated with a session. Just do a search in the forum for "OnHTTPCommand". Below is an example. procedure TUniServerModule.UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); var dm : TdmReportData; begin if ARequestInfo.URI='/report/finsummary' then begin dm := TdmReportData.Create(nil); try dm.qryReport.Connection := dm.FDConnection; AResponseInfo.ContentText := dm.GenerateReportPDF(repFinSummary, '') + ' header [user] = ' + ARequestInfo.RawHeaders.Values['user']; AResponseInfo.ResponseNo := 200; AResponseInfo.WriteContent; Handled := True; finally dm.Free; end; end; if ARequestInfo.URI='/report/sleep' then begin Sleep(10000); AResponseInfo.ResponseNo := 200; AResponseInfo.ContentText := 'Finished sleeping!'; AResponseInfo.WriteContent; Handled := True; end; end; 1 1 Quote Link to comment Share on other sites More sharing options...
hmdsadeghian Posted September 3, 2018 Share Posted September 3, 2018 for example in Delphi MVc Framework you can add a property to a method and expose that method . and in client side with uri you can using that function. Quote Link to comment Share on other sites More sharing options...
Kattes Posted February 18, 2019 Share Posted February 18, 2019 @GerhardV: I just tried what you suggested and it works fine as long as I do not add any header information. If I enter for example the following cURL command: curl "http://localhost:8077/report/sleep" -H "Authorization: ffff" I do not even enter the event handler and get the response curl: (52) Empty reply from server Do you have any idea, how to pass header information to the UniGUIServerModule and extract them? Quote Link to comment Share on other sites More sharing options...
Kattes Posted February 19, 2019 Share Posted February 19, 2019 Ok, my fault - I used a forbidden Keyword in my header (Authorization). In case of using anything else it works fine. Header values can be accessed easily. For example if I define a key "test" with a value "88" the following call will set "s" to "88". s := ARequestInfo.RawHeaders.Values['test']; Quote Link to comment Share on other sites More sharing options...
mhmda Posted February 19, 2019 Share Posted February 19, 2019 Unigui = Powerful WebApps, you may use it as Rest server but it is not built for that, we use mORMot https://synopse.info/fossil/wiki?name=SQLite3+Frameworkhttps://synopse.info/fossil/wiki?name=SQLite3+Framework for creating our API for our WebApp that built using unigui. Quote Link to comment Share on other sites More sharing options...
delagoutte Posted February 21, 2019 Share Posted February 21, 2019 mhmda : do you use your API as data provider for your unigui app or do you use firedac component with direct acces to db? Quote Link to comment Share on other sites More sharing options...
mhmda Posted February 21, 2019 Share Posted February 21, 2019 We use something like ORM between unigui and DB when it comes to CRUD operations. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.