Jump to content

Communication with external REST


uniguisyriusz

Recommended Posts

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? 

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...