Idhttpserver (INDY10) Development Rest Middleware
The browser queries the data URL sample by "Get": Http://127.0.0.1:7777/query?sql=select * from T1
/query means "query" command word
? The following is the SQL parameter
Service-Side code:
Procedure Tform1.idhttpserver1commandget (acontext:tidcontext; Arequestinfo:tidhttprequestinfo; Aresponseinfo:tidhttpresponseinfo);
Var
method, sql:string;
{$IFDEF ADO}
Dm:tfrmdmado;
{$ENDIF}
{$IFDEF ODAC}
Dm:tfrmdmodac;
{$ENDIF}
Begin
Method: = arequestinfo.document; //gets the command word
If method = "then
Exit;
{$ifdef ADO}
CoInitialize (nil);
{$endif}
Try
If method = '/query ' then //query data
begin
sql: = arequestinfo.params.values[' sql ']; //the SQL parameter
If sql = "then
Exit;
Aresponseinfo.responseno: = 0;
Aresponseinfo.contenttype: = ' text/html ';
{$IFDEF ADO}
DM: = tfrmdmado.create (nil);
{$ENDIF}
{$IFDEF Odac}
DM: = tfrmdmodac.create (nil);
{$ENDIF}
Try
Aresponseinfo.contenttext: = DM. Query (SQL); //returns the data that the data engine queries to in JSON format
Aresponseinfo.writecontent; //replies to the requester
finally
DM. Free;
End;
End;
except
on e:exception do
begin
End
End
{$ifdef ADO}
CoUninitialize;
{$ENDIF}
End
Idhttpserver (INDY10) Development Rest Middleware