Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Quickly And Easily Build A REST Based Notes App With RAD Server In Delphi And C++

EMS.NotesResource Sample is a server-client EMS demo.

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 sample. InterBase is used to store the information with the server connections. Use the RAD Server Console to display the statistics.

The first part consists of creating an EMS Package with a new ResourceName (Notes). Once you run the package, the resource is registered on the EMS server and can be accessed by a client application using REST.

The client needs 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 NotesResourcePackage project, the EMSDevServer starts automatically. If the configuration file is missing, a wizard launches.

  1. Navigate to the location given above and open:
    • Delphi: NotesResourcePackage.dpk
    • C++: NotesResourcePackageCpp.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 by 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 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.

The Delphi supported platforms for this sample are: 32-bit, 64-bit Windows, and iOS Simulator.

The C++ Supported platforms for this sample are: 32-bit and 64-bit.

  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\NotesResource\NotesClientProject.dproj.
    • C++: Start | Programs | Embarcadero RAD Studio Sydney | Samples\CPP\Database\EMS\NotesResource\NotesClientProjectCpp.cbproj.
  4. Press F9 or choose Run > Run.
  5. Insert a User name and Password and click Signup, or Login if you previously created an account.
  6. Click Add to add a new note.
  7. Write the note and click Save.

Implementation

EMS Package

The Resource Module has code to register a REST OverView API resource. The resource is called “Notes”. The resource defines a Get, GetItem, Post, PutItem, and DeleteItem method.

Once you run the package and have the EMS server running, as a test, you can invoke the GET method by using the browser http://localhost:8080/Notes.Note: An error message appears informing that you need to be logged in to access this information.

The NotesStorageU file defines the path of the notes.ini file where the created notes are saved.

Client Application

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 TBackendEndPoint for each method. This component identifies the name of a resource (Notes), the method used, and the ResourceSuffix.

The information is managed with TJSONObject and TJSONArray.

You can find attached a link below with the original post:

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

Exit mobile version