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.
- Navigate to the location given above and open:
- Delphi: NotesResourcePackage.dpk
- C++: NotesResourcePackageCpp.cbproj
- Press Shift+Ctrl+F9 or choose Run > Run Without Debugging.
- 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.
- When the Confirm dialog opens, click Yes.
- Leave all the parameters by default and go through the different windows by clicking Next.
- Click Finish to close the wizard.
- An Information window appears. Click OK.
- 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.
- To run the sample on iOS Simulator, change the URLHost property of the TEMSProvider component to the IP address from the machine you are launching the sample and running the server.Note: The TEMSProvider component is placed in the NotesClientModule unit.
The C++ Supported platforms for this sample are: 32-bit and 64-bit.
- On the Project Manager, right-click on ProjectGroup1.
- Click Add Existing Project….
- Navigate to:
- Delphi: Start | Programs | Embarcadero RAD Studio Sydney | SamplesObject PascalDataBaseEMSNotesResourceNotesClientProject.dproj.
- C++: Start | Programs | Embarcadero RAD Studio Sydney | SamplesCPPDatabaseEMSNotesResourceNotesClientProjectCpp.cbproj.
- Press F9 or choose Run > Run.
- Insert a User name and Password and click Signup, or Login if you previously created an account.
- Click Add to add a new note.
- 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