简体   繁体   中英

Delphi EMS FireDAC: How to pass parameter from client to server using EMS?

I am working on the simple client server application using EMS (ie: for future iOS application) in Delphi.

On the client unit, I have EMSProvider and EMSFireDACClient which fetches data from a Database (MSSQL) through a Datasource.

On the server unit, I have FDConnection and TFDQuery which deals with my Database. So far everything is working fine.

Question: Now I need to pass some parameters from client to the server and that fetches the result data. How should I do using EMS ? Any functions or procedures available in EMS ?

Regarding source code, everything was handled by corresponding components. So coding part is very less.

Thanks in advance.

An EMS call is like a REST call. You can pass further URL parameters both in the path (handled directly) -- see the default implementation of getting items by ID) and as extra query params. Those are in the request object. To pass them, use a custom Endpoint in the client.

Here is some more info:

Server declaration:

[ResourceSuffix('{item}')]
procedure GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);

Server implementation:

procedure TNotesResource1.GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
  LItem: string;
begin
  LItem := ARequest.Params.Values['item'];
  ...

Client configuration for endpoint:

object BackendEndpointGetNote: TBackendEndpoint
  Provider = EMSProvider1
  Auth = BackendAuth1
  Params = <
    item
      Kind = pkURLSEGMENT
      name = 'item'
      Options = [poAutoCreated]
    end>
  Resource = 'Notes'
  ResourceSuffix = '{item}'
end

Client call:

  BackendEndpointGetNote.Params.Items[0].Value := AID;
  BackendEndpointGetNote.Execute;

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM