4

I am working on the simple client server application using EMS (i.e: 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.

gagaouthu
  • 299
  • 1
  • 3
  • 9
A_R
  • 109
  • 2
  • 12

1 Answers1

3

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.

Marco Cantù
  • 1,195
  • 7
  • 13
  • Thanks for your reply. But can you tell me a bit more about the request object and how to use custom Endpoint in the client? Any examples? (I am newbie in this topic). – A_R Oct 23 '14 at 15:01
  • I have posted a another question related to this issue in the following [link](http://stackoverflow.com/questions/26631077/delphi-ems-firedac-cannot-open-dataset-fdmemtable). Could you help me to solve that issue? – A_R Oct 29 '14 at 14:43