Jump to content
uniGUI Discussion Forums
gerardocrisci

api rest in an unigui project

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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;
  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×