Tutorial: Implementing Your First RAD Server Client Application

From RAD Studio
Jump to: navigation, search

Go Up to RAD Server Client Application

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

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

  • TEMSProvider component is used to set up the connection with the RAD Server Engine.
  • TBackendEndpoint component is used to access a particular RAD Server Resource Endpoint method from your RAD Server Client application (one of the RAD Server Engine REST API methods). A RAD Server Client application calls the TBackendEndpoint to GET or POST JSON from/to the RAD Server Engine.
Note: Each TBackendEndpoint component is configured to access a RAD Server Resource Endpoint. Add as many TBackendEndpoint components a RAD Server 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 a RAD Server 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 RAD Server Engine parameters according to the RAD Server Engine configuration:
    • URLHost: localhost
    • URLPort: 8080
    • URLProtocol: http
  4. Click Test Connection button. If the connection is set up successfully, you will get a message with the current version of the RAD Server Engine (EMS Server).
  5. In the RAD Server Engine Window, the log pane shows the version request.

Calling a Resource Endpoint Method

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

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

  1. In your RAD Server Client application, drop a TBackendEndpoint component on the form.
  2. In the Object Inspector, set the following parameters of the TBackendEndpoint to use the RAD Server Engine 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
  3. If the parameters are properly set, you will get a successful response from the RAD Server Engine while testing the configuration of the TBackendEndpoint component. You can either:
  4. In the RAD Server Engine Window, the log pane shows the Version request.

Visually Binding Your Data

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

  1. Open the LiveBindings Designer to visually bind the response data for your RAD Server Client application. Select View > Tool Windows > 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.
  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);
    • C++:
    void __fastcall TForm1::Button1Click(TObject *Sender)
  6. Build and run your application.

See Also