uniguisyriusz Posted September 4, 2018 Share Posted September 4, 2018 I want to communicate with external REST to synchronize (bidirectional) data between UniGUI App database and windows apps database. REST is directly connected with windows app database. In UniGUI app i will make a form with button, on button click I will call REST and save readed data to database. It is possible to fire this action without entering webbrowser and manually click button? For example via URL? This would help to make data synchronization automatic. Mayby someone can propose other way to do this? Quote Link to comment Share on other sites More sharing options...
Luciano Benito Posted September 4, 2018 Share Posted September 4, 2018 Boa tarde, é possivel fazer isso com o RestClient + TTimer, você pode implementar no Unigui. Dá uma olhada no (REST Demo do Delphi). http://docwiki.embarcadero.com/CodeExamples/Tokyo/en/REST.RESTDemo_Sample Att. Luciano Benito Quote Link to comment Share on other sites More sharing options...
GerhardV Posted September 5, 2018 Share Posted September 5, 2018 You can use the "OnHTTPCommand" event in the UniServerModule. procedure TUniServerModule.UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); var RC : TRESTClient; begin RC := TRESTClient.Create; try if ARequestInfo.URI='/data/synchronizer' then begin // DO YOUR REST STUFF AResponseInfo.ResponseNo := 200; AResponseInfo.ContentText := 'Synchronization done!'; Handled := True; end; finally RC.Free; end; end; You can then call it like this: ...localhost:8077/data/synchronizer 1 Quote Link to comment Share on other sites More sharing options...
uniguisyriusz Posted September 5, 2018 Author Share Posted September 5, 2018 Thanks Gerhard V. Its working good. Quote Link to comment Share on other sites More sharing options...
albertovesx Posted September 6, 2018 Share Posted September 6, 2018 You can use the "OnHTTPCommand" event in the UniServerModule. procedure TUniServerModule.UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); var RC : TRESTClient; begin RC := TRESTClient.Create; try if ARequestInfo.URI='/data/synchronizer' then begin // DO YOUR REST STUFF AResponseInfo.ResponseNo := 200; AResponseInfo.ContentText := 'Synchronization done!'; AResponseInfo.WriteContent; Handled := True; end; finally RC.Free; end; end; You can then call it like this: ...localhost:8077/data/synchronizer Is this UniGUIServerModuleHTTPCommand like having webbroker inside unigui app? Does it creates a thread for each request? Quote Link to comment Share on other sites More sharing options...
GerhardV Posted September 6, 2018 Share Posted September 6, 2018 The UniGUI server is based on Indy's HTTP server, so yes it would create a thread for each request but the request is not associated with any session. Also please take note that there is no security in the above example, you would need to implement some authentication mechanism yourself. Farshad please correct me if I am wrong. 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.