Delphi EMS FireDAC: how to transfer parameter from client to server using EMS?

I am working on a simple client server application using EMS(for example, for future iOS application) in Delphi.

On the client device, I have EMSProvider, and EMSFireDACClientthat retrieves data from a database (MSSQL) through the data source.

On the server block I have FDConnectionand TFDQuerywhich concerns my database. So far, everything is working fine.

Question: Now I need to transfer some parameters from the client to the server and get the result data. How do i use EMS? Any features or procedures available in EMS?

Regarding the source code, everything was handled by the corresponding components. Thus, the encoding part is very smaller.

Thanks in advance.

+4
source share
1 answer

An EMS call is like a REST call. You can pass additional URL parameters both in the path (processed directly) - see the default implementation for receiving elements by identifier), and as additional request parameters. They are in the request object. To transfer them, use the user 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.

+2

All Articles