Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Build High Performance REST Services With This Server-Client EMS FireDAC Demo In Delphi

This sample demonstrates how to use an EMS package to extend the EMS Server to connect to an SQLite database using FireDAC components.

he sample accesses an SQLite database. The connection parameters are defined in the TFDConnection component. If you experience problems with the connection verify these parameters.

It requires InterBase to be installed on the machine or to connect to a remote server. Make sure that the server is running before you run the example. InterBase is used to store the information about the server connections. You can use the RAD Server Console to display the statistics.

Location

You can find the FireDACResource sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to either:
    • Object Pascal\DataBase\EMS\FireDACResource
    • CPP\Database\EMS\FireDACResource
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The first part consists of creating an EMS Package with a TDataModule where the FireDAC components are placed. It uses the TFDConnection component to establish the connection to the SQLite database. Once you run the package, the resource is registered on the EMS server and can be accessed by a client application using REST.

The FireDAC client needs a TEMSFireDACClient and a TEMSProvider to connect to the EMS Server and to retrieve the JSON data.

How to Use the Sample

Run the EMS Package

When you run the SampleEMSFireDACResourcePackage project, the EMSDevServer starts automatically. If the configuration file is missing, a wizard launches.

  1. Navigate to the location given above and open:
    • Delphi: SampleEMSFireDACResourcePackage.dpk
    • C++: SampleEMSFireDACResourcePackageCpp.cbproj
  2. Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
  3. The EMS Development Server opens. If it is the first time you are using EMS on the machine, you need to run the configuration wizard in order to create the EMS server configuration file.
    1. When the Confirm dialog opens, click Yes.
    2. Leave all the parameters by default and go through the different windows clicking Next.
    3. Click Finish to close the wizard.
    4. An Information window appears. Click OK.
  4. The server starts automatically. Minimize it.

Run the FireDAC Client Application

The client expects the EMSDevServer to be running at localhost:8080. If you are running the server at a different address, modify the properties of the TEMSProvider component.

  1. On the Project Manager, right-click on ProjectGroup1.
  2. Click Add Existing Project….
  3. Navigate to:
    • Delphi: Start | Programs | Embarcadero RAD Studio Sydney | Samples\Object Pascal\DataBase\EMS\FireDACResource\SampleEMSFireDACClient.dproj
    • C++: Start | Programs | Embarcadero RAD Studio Sydney | Samples\CPP\Database\EMS\FireDACResource\SampleEMSFireDACClientCpp.cbproj
  4. Press F9 or choose Run > Run.
  5. Click Get Tables to load the data from the SQLite database.
  6. Do some changes on the records and click Post Updates to commit the changes.

Implementation

EMS Package

The Resource Module has code to register a REST API resource. The resource is called “test”. The resource defines a GET and a POST method.

Once you run the package and have the EMS server running, as a test, you can invoke the GET method using the browser http://localhost:8080/test.

FireDAC Client

The client application has a TEMSProvider component. This component identifies the address of the RAD Server Engine (EMS Server) (http://localhost:8080).

The client application also has a TEMSFireDACClient . This component identifies the name of a resource (test).

  • EMSFireDACClient1.GetData accesses http://localhost:8080/test with HTTP GET. JSON is returned by the GET.
  • EMSFireDACClient1.PostUpdates accesses http://localhost:8080/test with HTTP POST. JSON is sent with the POST.

Please follow the link below if you want to check the original post:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/EMS.FireDACResource_Sample

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES