Tutorial: Implementing Your First EMS Client Application

From RAD Studio
Jump to: navigation, search

Go Up to EMS Client Application


You can create an EMS Client application to connect to the EMS Server through the REST API that the EMS Server exposes. To access the EMS Server Resources and information from the EMS database, you can use either the built-in API or your custom API resource.

In this tutorial, you need the following components in your EMS Client application:

  • TEMSProvider component is used to set up the connection with the EMS Server.
  • TBackendEndpoint component is used to access a particular EMS Resource Endpoint method from your EMS Client application (one of the EMS Server REST API methods). An EMS Client application calls the TBackendEndpoint to GET or POST JSON from/to the EMS Server.
Note: Each TBackendEndpoint component is configured to access an EMS Resource Endpoint. Add as many TBackendEndpoint components as EMS Resource Endpoint methods are accessed.

To make a call to a REST API Endpoint, you need to select the proper method in the Method property of the TBackendEndpoint component.

Creating an EMS Client

  1. Create a new Multi-Device Application:
    • For Delphi: Open File > New > Multi-Device Application - Delphi
    • For C++: Open File > New > Multi-Device Application - C++Builder
  2. In the Tool Palette, search for a TEMSProvider component and drop it on the form.
  3. In the Object Inspector, configure the EMS server parameters according to the EMS server configuration:
    • URLHost: localhost
    • URLPort: 8080
    • URLProtocol: http
    EMSServerConnection.png
  4. Click Test Connection button. If the connection is set up successfully, you will get a message with the current version of the EMS Server.
    InfoVersionEMSServer.png
  5. In the EMS Server Window, the log pane shows the version request.
    InfoVersionEMSServerLog.png

Calling a Resource Endpoint Method

You can call the EMS Server resource endpoints to retrieve or set data by making REST API calls from your EMS Client application.

You can use either the EMS Administrative API endpoint methods from your EMS Server or the custom resource endpoints that extend the EMS Server functionality.

  1. In your EMS Client application, drop a TBackendEndpoint component on the form.
  2. In the Object Inspector, set the following parameters of the TBackendEndpoint to use the EMS Server resource:
    • Provider. In the drop-down list, select the name of the TEMSProvider component (EMSProvider1).
    • Resource: Version
    • Resource suffix: Leave it blank for this tutorial.
    • Method: rmGET
    TBackendEndpointConfiguration.png
  3. If the parameters are properly set, you will get a successful response from the EMS Server while testing the configuration of the TBackendEndpoint component. You can either:
    TBackendEndpointResponse.png
  4. In the EMS Server Window, the log pane shows the Version request.
    UsersGetEMSServerLog.png

Visually Binding Your Data

You can visually bind the response data (from the EMS Server) to a component in your EMS Client application.

  1. Open the LiveBindings Designer to visually bind the response data for your EMS Client application. Select View > LiveBindings Designer
  2. In the LiveBindings Designer, right-click the Response.JSONText property of the TBackendEndpoint component and choose the Link to new control option to link the response to a new TMemo component.
    EMSClientDesignView.png EMSClientLiveBindingDesigner.png
  3. Drop a TLabel on the form.
  4. Drop a new TButton component on your form.
  5. Create the OnClick event of the TButton component (double-click on it) and add the following code:
    • Delphi:
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        BackendEndpoint1.Execute;
    end;
    
    • C++:
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        BackendEndpoint1->Execute();
    }
    
  6. Build and run your application.
    EMSClientExecution.png

See Also