[See the full index of articles for more information]
Table of Contents:
In this blog post, you’ll learn how to build your first RAD Server service-based applications using Delphi and C++Builder. Before you begin development, you’ll want to make sure that your InterBase database server is running. RAD Server uses an InterBase database for the storage of user information, user groups, analytics, registered devices, version information, registered Edge Modules, push notification messages and more.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/3681.image001.png?w=750&ssl=1)
Figure 1: InterBase 2017 Server Manager
1. Using the RAD Server Project Wizard
The fastest way to get started is to use the New Projects menu (File | New | Other…) and choose the RAD Server | RAD Server Package wizard for Delphi or C++Builder.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/6644.pastedimage1557266819656v1.png?w=750&ssl=1)
Figure 2: RAD Server Project Wizard choices for Delphi and C++
Select the RAD Server Package project. A wizard will appear to help create the starting project. On the first page choose how the wizard will create the resources and endpoints that will appear in the RAD Server application. The RAD Server Package Wizard provides two choices to proceed.
Choice 1: Create an empty package that does not register a resource. Choose this option if you are going to add your resources later. Using this choice, a package project will be created with a starting main library.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/3173.image005.png?w=750&ssl=1)
Figure 3: Create an empty RAD Server package
Clicking the Finish button will create the starting project for additional development work to create the finished RAD Server application.
Choice 2: Create a package with a resource that extends the REST API of for the RAD Server. Click the Next Button and two additional wizard steps will appear to help create the package project, resource and endpoints. To build the first RAD Server project make this choice.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/5148.image007.png?w=750&ssl=1)
Figure 4: Create a resource based RAD Server package
On the wizard’s second page set the Resource name to “Test”. The File type radio buttons presents two options: 1) create a unit for implementing the resource in code, and 2) create a data module for implementing the resource using the IDE’s designer, components and code editor. For this first RAD Server application chose to use a Data Module.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/3581.image009.png?w=750&ssl=1)
Figure 5: RAD Server Package Wizard page 2 – set the resource name and file type
Click the Next button to create a starting set of endpoints.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/3581.image011.png?w=750&ssl=1)
Figure 6: RAD Server Package Wizard page 3 – choose starting EndPoints
On the wizard’s third page choose from a set of predefined EndPoints: Get (REST GET), GetItem (REST GET with a segment at the end of the URL that identifies the item to get) , Post (REST Post), PutItem (REST Put with a segment at the end of the URL that identifies the item to put), and DeleteItem (REST Delete with a segment at the end of the URL that identifies the item to delete). There is also a Select/deselect all check box at the bottom of the EndPoints list.
To create a package project with all of the EndPoints defined, click on all of the starting end points or choose Select All.
You can also step back through the wizard or click on the step links to make changes to the Package, Resource and Endpoints. To create your starting project is to click the Finish button.
After the wizard completes, you are placed back in the IDE. The first thing to do is to save the project. For the C++ and Delphi data module, use the name “MyDMUnit”. For the C++ project and package use the name “MyFirstCppRADServerPackage”. For the Delphi project and package use the name “MyFirstDelphiRADServerPackage”.
2. The Wizard Generated RAD Server Project and Source Code
Here are the projects and source code created by the wizard for Delphi and C++. For the C++ code I have added a couple of lines of code in the Get and GetItem endpoint implementations to set the response (look for the // sample code comment line in MyDMUnit.cpp).
Delphi:
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/3581.image013.png?w=750&ssl=1)
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/7215.image015.png?w=750&ssl=1)
Figure 7: Generated Delphi project and Figure 8: Generated Delphi resource module
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<span style="font-family:inherit;font-size:inherit;"><span style="color:#000084;font-weight:bold;">package</span> MyFi</span>rstDelphiRADServerPackage; <span style="color:#000084;">{$R *.res}</span> <span style="color:#000084;">{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}</span> <span style="color:#000084;">{$ALIGN 8}</span> <span style="color:#000084;">{$ASSERTIONS ON}</span> <span style="color:#000084;">{$BOOLEVAL OFF}</span> <span style="color:#000084;">{$DEBUGINFO OFF}</span> <span style="color:#000084;">{$EXTENDEDSYNTAX ON}</span> <span style="color:#000084;">{$IMPORTEDDATA ON}</span> <span style="color:#000084;">{$IOCHECKS ON}</span> <span style="color:#000084;">{$LOCALSYMBOLS ON}</span> <span style="color:#000084;">{$LONGSTRINGS ON}</span> <span style="color:#000084;">{$OPENSTRINGS ON}</span> <span style="color:#000084;">{$OPTIMIZATION OFF}</span> <span style="color:#000084;">{$OVERFLOWCHECKS OFF}</span> <span style="color:#000084;">{$RANGECHECKS OFF}</span> <span style="color:#000084;">{$REFERENCEINFO ON}</span> <span style="color:#000084;">{$SAFEDIVIDE OFF}</span> <span style="color:#000084;">{$STACKFRAMES ON}</span> <span style="color:#000084;">{$TYPEDADDRESS OFF}</span> <span style="color:#000084;">{$VARSTRINGCHECKS ON}</span> <span style="color:#000084;">{$WRITEABLECONST OFF}</span> <span style="color:#000084;">{$MINENUMSIZE 1}</span> <span style="color:#000084;">{$IMAGEBASE $400000}</span> <span style="color:#000084;">{$DEFINE DEBUG}</span> <span style="color:#000084;">{$ENDIF IMPLICITBUILDING}</span> <span style="color:#000084;">{$RUNONLY}</span> <span style="color:#000084;">{$IMPLICITBUILD ON}</span> <span style="color:#000084;font-weight:bold;">requires</span> rtl, emsserverapi; <span style="color:#000084;font-weight:bold;">contains</span> MyDMUnit <span style="color:#000084;font-weight:bold;">in</span> <span style="color:#0000ff;">'MyDMUnit.pas'</span> <span style="color:#808080;">{TestResource1: TDataModule}</span>; <span style="color:#000084;font-weight:bold;">end</span>. |
|
MyDMUnit.pas:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
<span style="color:#000084;font-weight:bold;">unit</span> MyDMUnit; <span style="color:#808080;">// EMS Resource Module</span> <span style="color:#000084;font-weight:bold;">interface</span> <span style="color:#000084;font-weight:bold;">uses</span> System.SysUtils, System.Classes, System.JSON, EMS.Services, EMS.ResourceAPI, EMS.ResourceTypes; <span style="color:#000084;font-weight:bold;">type</span> [ResourceName(<span style="color: #0000ff;">'Test'</span>)] TTestResource1 = <span style="color:#000084;font-weight:bold;">class</span>(TDataModule) <span style="color:#000084;font-weight:bold;">published</span> <span style="color:#000084;font-weight:bold;">procedure</span> Get(<span style="color:#000084;font-weight:bold;">const</span> AContext: TendpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); [ResourceSuffix(<span style="color: #0000ff;">'{item}'</span>)] <span style="color:#000084;font-weight:bold;">procedure</span> GetItem(<span style="color:#000084;font-weight:bold;">const</span> AContext: TendpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">procedure</span> Post(<span style="color:#000084;font-weight:bold;">const</span> AContext: TendpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); [ResourceSuffix(<span style="color: #0000ff;">'{item}'</span>)] <span style="color:#000084;font-weight:bold;">procedure</span> PutItem(<span style="color:#000084;font-weight:bold;">const</span> AContext: TendpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); [ResourceSuffix(<span style="color: #0000ff;">'{item}'</span>)] <span style="color:#000084;font-weight:bold;">procedure</span> DeleteItem(<span style="color:#000084;font-weight:bold;">const</span> AContext: TendpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">implementation</span> <span style="color:#808080;">{%CLASSGROUP 'System.Classes.TPersistent'}</span> <span style="color:#000084;">{$R *.dfm}</span> <span style="color:#000084;font-weight:bold;">procedure</span> TTestResource1.Get(<span style="color:#000084;font-weight:bold;">const</span> AContext: TEndpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">begin</span> <span style="color:#808080;">// Sample code</span> AResponse.building.SetValue(TJSONString.Create(<span style="color:#0000ff;">'Test'</span>), <span style="color:#000084;font-weight:bold;">True</span>) <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">procedure</span> TTestResource1.GetItem(<span style="color:#000084;font-weight:bold;">const</span> AContext: TEndpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">var</span> LItem: <span style="color:#000084;font-weight:bold;">string</span>; <span style="color:#000084;font-weight:bold;">begin</span> LItem := ARequest.Params.Values[<span style="color: #0000ff;">'item'</span>]; <span style="color:#808080;">// Sample code</span> AResponse.building.SetValue(TJSONString.Create(<span style="color:#0000ff;">'Test '</span> + LItem), <span style="color:#000084;font-weight:bold;">True</span>) <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">procedure</span> TTestResource1.Post(<span style="color:#000084;font-weight:bold;">const</span> AContext: TEndpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">begin</span> <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">procedure</span> TTestResource1.PutItem(<span style="color:#000084;font-weight:bold;">const</span> AContext: TEndpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">var</span> LItem: <span style="color:#000084;font-weight:bold;">string</span>; <span style="color:#000084;font-weight:bold;">begin</span> LItem := ARequest.Params.Values[<span style="color: #0000ff;">'item'</span>]; <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">procedure</span> TTestResource1.DeleteItem(<span style="color:#000084;font-weight:bold;">const</span> AContext: TEndpointContext; <span style="color:#000084;font-weight:bold;">const</span> ARequest: TEndpointRequest; <span style="color:#000084;font-weight:bold;">const</span> AResponse: TEndpointResponse); <span style="color:#000084;font-weight:bold;">var</span> LItem: <span style="color:#000084;font-weight:bold;">string</span>; <span style="color:#000084;font-weight:bold;">begin</span> LItem := ARequest.Params.Values[<span style="color: #0000ff;">'item'</span>]; <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">procedure</span> <span style="color:#000084;font-weight:bold;">Register</span>; <span style="color:#000084;font-weight:bold;">begin</span> RegisterResource(TypeInfo(TTestResource1)); <span style="color:#000084;font-weight:bold;">end</span>; <span style="color:#000084;font-weight:bold;">initialization</span> <span style="color:#000084;font-weight:bold;">Register</span>; <span style="color:#000084;font-weight:bold;">end</span>. |
|
C++:
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/1030.image017.png?w=750&ssl=1)
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/2816.image019.png?w=750&ssl=1)
Figure 9: Generated C++ project and Figure 10: Generated C++ resource module
MyFirstCppRADServerPackage.cpp:
|
<span style="color:#808080;">// EMS Package</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">System.hpp</span><span style="color:#0000ff;">></span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> hdrstop</span> USEFORM(<span style="color:#0000ff;">"</span><span style="color:#0000ff;">MyDMUnit.cpp</span><span style="color:#0000ff;">"</span>, TestResource1); <span style="color:#808080;">/* TDataModule: File Type */</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> package(smart_init)</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#808080;">// Package source.</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> argsused</span> <span style="color:#000084;font-weight:bold;">extern</span> <span style="color:#0000ff;">"</span><span style="color:#0000ff;">C</span><span style="color:#0000ff;">"</span> <span style="color:#000084;font-weight:bold;">int</span> _libmain(<span style="color:#000084;font-weight:bold;">unsigned</span> <span style="color:#000084;font-weight:bold;">long</span> reason) { <span style="color:#000084;font-weight:bold;">return</span> 1; } <span style="color:#808080;">//---------------------------------------------------------------------------</span> |
|
MyDMUnit.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<span style="color:#808080;">// EMS Resource Modules</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;">ifndef</span><span style="color:#000084;"> MyDMUnitH</span> <span style="color:#000084;">#</span><span style="color:#000084;">define</span><span style="color:#000084;"> MyDMUnitH</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">System.Classes.hpp</span><span style="color:#0000ff;">></span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">System.SysUtils.hpp</span><span style="color:#0000ff;">></span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">EMS.Services.hpp</span><span style="color:#0000ff;">></span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">EMS.ResourceAPI.hpp</span><span style="color:#0000ff;">></span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">EMS.ResourceTypes.hpp</span><span style="color:#0000ff;">></span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> explicit_rtti methods (public)</span> <span style="color:#000084;font-weight:bold;">class</span> TTestResource1 : <span style="color:#000084;font-weight:bold;">public</span> TDataModule { <span style="color:#000084;font-weight:bold;">__published</span>: <span style="color:#000084;font-weight:bold;">private</span>: <span style="color:#000084;font-weight:bold;">public</span>: <span style="color:#000084;font-weight:bold;">__fastcall</span> TTestResource1(TComponent* Owner); <span style="color:#000084;font-weight:bold;">void</span> Get(TEndpointContext* AContext, TEndpointRequest* Arequest, TEndpointResponse* AResponse); <span style="color:#000084;font-weight:bold;">void</span> GetItem(TEndpointContext* AContext, TEndpointRequest* Arequest, TEndpointResponse* AResponse); <span style="color:#000084;font-weight:bold;">void</span> Post(TEndpointContext* AContext, TEndpointRequest* Arequest, TEndpointResponse* AResponse); <span style="color:#000084;font-weight:bold;">void</span> PutItem(TEndpointContext* AContext, TEndpointRequest* Arequest, TEndpointResponse* AResponse); <span style="color:#000084;font-weight:bold;">void</span> DeleteItem(TEndpointContext* AContext, TEndpointRequest* Arequest, TEndpointResponse* AResponse); }; <span style="color:#000084;">#</span><span style="color:#000084;">endif</span> MyDMUnit.cpp: <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> hdrstop</span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;">"</span><span style="color:#3f3fbf;">MyDMUnit.h</span><span style="color:#0000ff;">"</span> <span style="color:#000084;">#</span><span style="color:#000084;">include </span><span style="color:#0000ff;"><</span><span style="color:#3f3fbf;">memory</span><span style="color:#0000ff;">></span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> package(smart_init)</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> classgroup </span><span style="color:#0000ff;font-weight:bold;">"System.Classes.TPersistent"</span> <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> resource </span><span style="color:#0000ff;font-weight:bold;">"*.dfm"</span> <span style="color:#808080;">//---------------------------------------------------------------------------</span> <span style="color:#000084;font-weight:bold;">__fastcall</span> TTestResource1::TTestResource1(TComponent* Owner) : TDataModule(Owner) { } <span style="color:#000084;font-weight:bold;">void</span> TTestResource1::Get(TEndpointContext* Acontext, TEndpointRequest* ARequest, TEndpointResponse* AResponse) { <span style="color:#808080;">// Sample code</span> AResponse->building->SetValue(<span style="color:#000084;font-weight:bold;">new</span> TJSONString(<span style="color:#0000ff;">"</span><span style="color:#0000ff;">Test</span><span style="color:#0000ff;">"</span>), True);} <span style="color:#000084;font-weight:bold;">void</span> TTestResource1::GetItem(TEndpointContext* Acontext, TEndpointRequest* ARequest, TEndpointResponse* AResponse) { <span style="color:#000084;font-weight:bold;">String</span> item; item = ARequest->Params->Values[<span style="color: #0000ff;">"</span><span style="color: #0000ff;">item</span><span style="color: #0000ff;">"</span>]; <span style="color:#808080;">// Sample code</span> AResponse->building->SetValue(<span style="color:#000084;font-weight:bold;">new</span> TJSONString(<span style="color:#0000ff;">"</span><span style="color:#0000ff;">Test </span><span style="color:#0000ff;">"</span>+item), True); } <span style="color:#000084;font-weight:bold;">void</span> TTestResource1::Post(TEndpointContext* Acontext, TEndpointRequest* ARequest, TEndpointResponse* AResponse) { } <span style="color:#000084;font-weight:bold;">void</span> TTestResource1::PutItem(TEndpointContext* Acontext, TEndpointRequest* ARequest, TEndpointResponse* AResponse) { <span style="color:#000084;font-weight:bold;">String</span> item; item = ARequest->Params->Values[<span style="color: #0000ff;">"</span><span style="color: #0000ff;">item</span><span style="color: #0000ff;">"</span>]; } <span style="color:#000084;font-weight:bold;">void</span> TTestResource1::DeleteItem(TEndpointContext* Acontext, TEndpointRequest* ARequest, TEndpointResponse* AResponse) { <span style="color:#000084;font-weight:bold;">String</span> item; item = ARequest->Params->Values[<span style="color: #0000ff;">"</span><span style="color: #0000ff;">item</span><span style="color: #0000ff;">"</span>]; } <span style="color:#000084;font-weight:bold;">static</span> <span style="color:#000084;font-weight:bold;">void</span> Register() { std::<span style="color:#000084;font-weight:bold;">auto_ptr</span><TEMSResourceAttributes> attributes( <span style="color:#000084;font-weight:bold;">new</span> TEMSResourceAttributes()); attributes->ResourceName = <span style="color:#0000ff;">"</span><span style="color:#0000ff;">Test</span><span style="color:#0000ff;">"</span>; attributes->ResourceSuffix[<span style="color: #0000ff;">"</span><span style="color: #0000ff;">GetItem</span><span style="color: #0000ff;">"</span>] = <span style="color:#0000ff;">"</span><span style="color:#0000ff;">{item}</span><span style="color:#0000ff;">"</span>; attributes->ResourceSuffix[<span style="color: #0000ff;">"</span><span style="color: #0000ff;">PutItem</span><span style="color: #0000ff;">"</span>] = <span style="color:#0000ff;">"</span><span style="color:#0000ff;">{item}</span><span style="color:#0000ff;">"</span>; attributes->ResourceSuffix[<span style="color: #0000ff;">"</span><span style="color: #0000ff;">DeleteItem</span><span style="color: #0000ff;">"</span>] = <span style="color:#0000ff;">"</span><span style="color:#0000ff;">{item}</span><span style="color:#0000ff;">"</span>; RegisterResource(__typeinfo(TTestResource1), attributes.release()); } <span style="color:#000084;">#</span><span style="color:#000084;font-weight:bold;">pragma</span><span style="color:#000084;font-weight:bold;"> startup Register 32</span> |
|
3. Configuring your first RAD Server Application
Now that you’ve used the wizard to build your first RAD Server application, you can use the IDE to compile and test the application. The IDE uses the EMSDevServer as the host executable (EMDDevServer.exe) to start execution with the parameter being the package file to load. There are two versions of the EMSDevServer for Win32 and Win64 development ($(BDS)binEMSDevServer.exe and $(BDS)bin64EMSDevServer.exe).
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/4162.image021.png?w=750&ssl=1)
Figure 11: Run | Parameters… dialog showing EMSDevServer.exe as the Host application
RAD Studio also includes EMSDevConsole.exe which will start the EMSDevConsole server and open the EMS Console Server Window. The EMS Console provides a web application which displays analytics, provides for user/group management, and more for your RAD Server application.
Choose the Run | Run menu item or hit F9 to compile, link and run the starting application. The RAD Server Development Server will start, by default, using TCP port 8080. The RAD Server Development Console uses, by default, port 8081.
If this is the first time that you’ve tried to run a RAD Server Application you will see a dialog box that says the RAD Server configuration file, emsserver.ini, was not found. This happens when there is no RAD Server registry key or if the configuration file does not exist.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/1586.image023.png?w=750&ssl=1)
Figure 12: Trying to start the RAD Server Development Server without a configuration file
Click the Yes button to run the RAD Server configuration wizard.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/2018.image025.png?w=750&ssl=1)
Figure 13: RAD Server setup wizard page 1 – specify the new EMS database connection parameters
In the first wizard step, enter the InterBase server instance (by default RAD Studio’s development version of InterBase Server uses gds_db). If you previously installed InterBase using a different server instance name, enter that name string. This wizard page also contains the name for the RAD Server database (emsserver.ib), and directory that will contain the database and configuration file.
Click the Next button to tell the wizard whether you to create sample RAD Server database data for users and user groups. For development and testing we’ll set both check boxes.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/0456.image027.png?w=750&ssl=1)
Figure 14: RAD Server setup wizard page 2 – choose to generate sample data for the database
Click the Next button to set up the user name and password for logging into the RAD Server console.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/7128.image029.png?w=750&ssl=1)
Figure 15: RAD Server setup wizard page 2 – choose a Console user name and password
Click the Next button to go to the final wizard step. The wizard is ready to create the RAD Server database file, configuration file, and set the Windows registry key for the currently logged in user.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/8284.image031.png?w=750&ssl=1)
Figure 16: Final RAD Server configuration wizard page
This page displays the database file path and name, configuration path and name and the Windows Registry key. You can always make changes to the RAD Server configuration file (emsserver.ini) at any time. Click the Finish button. A confirmation dialog will appear with a reminder that the configuration will use an instance of InterBase that does not have a RAD Server license. The development license limits your RAD Server application to a maximum of 5 users.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/1351.image033.png?w=750&ssl=1)
Figure 17: Confirmation dialog box – using InterBase instance without a RAD Server license
When you are ready to deploy your RAD Server application, you’ll be able to use your deployment licenses for RAD Server and InterBase.
Click the Yes button. The wizard will display location of the emsserver.ini configuration file. It also lists the sample data that has been added to the database.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/8688.image035.png?w=750&ssl=1)
Figure 18: List of RAD Server files created by the configuration wizard
Click the OK button. Two files now appear in the C:UsersPublicDocumentsEmbarcaderoEMS directory.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/7563.image037.png?w=750&ssl=1)
Figure 19: Files on disk created by the RAD Server configuration wizard
You can use InterBase’s IBConsole program to view the emsserver.ib database.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/5545.image039.png?w=750&ssl=1)
Figure 20: IBConsole view of the emsserver.ib database file
Use RegEdit to view the registry key created for the RAD Server configuration file location.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/4606.image041.png?w=750&ssl=1)
Figure 21: RAD Server configuration file registry key
4. Testing your first RAD Server Application
When the RAD Server configuration server is created, the RAD Server Development Server will start executing. On my development computer, the EMSDevServer reports that the default port (8080) is already in use because some other application (Tomcat Server, another web server or some other running application) is already using the port 8080.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/3482.image043.png?w=750&ssl=1)
Figure 22: The RAD Server application cannot start – the default port is already in use.
To fix this problem, Click the OK button.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/8272.image045.png?w=750&ssl=1)
Figure 23: RAD Server Development Server not started due to a port conflict
You can use the edit box to enter an unused port number (I chose port 8087). Click the Start button and, if the new port number is unused, the RAD Server Development server will start running for this first launch.
To make the port change permanent for your all of your development work, edit the RAD Server development emsserver.ini configuration file. Use a text editor to open the emsserver.ini file. Search for the [Server.Connection.Dev] section. Edit the unused port number and save the configuration file
[Server.Connection.Dev]
Port=8087
The RAD Server configuration file will be covered in more detail in the chapter titled “RAD Server Configuration INI File Explaned”.
When you hit run in the IDE your RAD Server Development Server will start executing and the Log will show the operations that take place for your package application.
C++ Version:
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/1882.image047.png?w=750&ssl=1)
Figure 24: RAD Server Development Server starting the first C++ application package
Delphi Version:
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/6138.image049.png?w=750&ssl=1)
Figure 25: RAD Server Development Server starting the first Delphi application package
The RAD Server Development Server log will display the configuration, database connection, licensing information, the application package that was loaded, the resources that were registered, and endpoints that were created.
Clicking the Open Browser button will start your default browser and display the JSON result of calling the GetVersion built-in endpoint. You’ve now used your first RAD Server REST endpoint!
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/8738.image051.png?w=750&ssl=1)
Figure 26: Browser showing the output from calling the version endpoint
In the browser, change the URL to localhost:8087/Test and hit enter. The browser will receive the JSON response from the Get endpoint.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/4075.image053.png?w=750&ssl=1)
Figure 27: Browser showing the JSON output from the Test resource’s Get method
If you pass an additional item on the URL, the GetItem endpoint will be called, and the code behind will return a JSON string containing the resource name plus the item you typed.
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/5141.image055.png?w=750&ssl=1)
Figure 28: Browser showing the JSON output from the Test resource’s GetItem method
For simple examples it’s okay to return a JSON string, but for larger, more complex data structures, you may not want to return a large JSON string. RAD Studio provides many other ways to generate JSON data including using JSON objects, JSON streams and the JSON writer.
Edit the URL to use the “Users” resource which will call the default GetUsers endpoint to display JSON for the user generated by the RAD Server configuration wizard in the RAD Server datastore (there is only one to start).
![](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/7217.image057.png?w=750&ssl=1)
Figure 29: JSON response in the Browser for a call to the GetUsers end point
You’ve now used four of the endpoints that were generated by the RAD Server project wizard.
5. See Also
RAD Server’s Enterprise Mobility Services (EMS)
http://docwiki.embarcadero.com/RADStudio/en/Enterprise_Mobility_Services_(EMS)
Setting Up Your RAD Studio (EMS) Server
http://docwiki.embarcadero.com/RADStudio/en/Setting_Up_Your_EMS_Server
Configuring Your EMS Server or EMS Console Server on Windows
http://docwiki.embarcadero.com/RADStudio/en/Configuring_Your_EMS_Server_or_EMS_Console_Server_on_Windows