REST Server Tutorial

ReportBuilder REST Services allows for the simple creation of a report REST server that may be accessed via any mobile device using the mobile client components. This article gives an overview of the REST Services components, how they are used, as well as a simple tutorial.

The ReportBuilder REST Service components are installed into the Delphi Component Pallet and are available for Win32 and Win64 VCL platforms. These components provide the means necessary to generate and transfer reports built with ReportBuilder to a REST client residing on the platform of choice. Below is a brief description of each component.

  • RESTServerComponentsTrbRestService: Represents the ReportBuilder REST Service. Use RestService to build a REST server application. This component typically resides on a web module and then a TDataModule is used to implement a report module, which hosts the TppRestReportProvider and TppReportDirectory components.
  • TrbRestReportProvider: Use RestReportProvider to implement a report module for a TrbRestService application.
  • TrbReportDirectory: Use ReportDirectory to represent a collection of reports or archives in a REST server application.

 

Below is a quick tutorial on how to create a REST server.  Once the server is completed see the following article/tutorial on creating a REST client.
https://rbwiki.digital-metaphors.com/rest/rest-client/client-tutorial-fmx/

 

Tutorial: Creating a simple file REST server

1. Select File | New | Other from the Delphi main menu. From there navigate to the Web Broker section and create a new Web Server Application. Follow the wizard instructions and create a stand-alone Windows VCL app. Define a valid port for your server to use (ex. 8080) and finish the wizard.
RESTServer1

 

 

 

 

 

 

 

2. Notice in addition to the main server form, a WebModule has been added to the probject. Open the WebModule.
RESTServer2

 

 

 

 

– Add a TrbRestService component to the WebModule.
RESTServer3

 

 

 

 

 

 

– Assign a meaningful value to the ServiceName property of the TrbRestService object. This will be how the client accesses the REST service.
RESTServer3-1

 

 

 

 

– Add code to the Default Handler Action event to process the request:

if rbRestService.IsServiceRequest(String(Request.PathInfo)) then
  rbRestService.ProcessWebRequest(Request, Response)
else
...

 

3. Add a DataModule to the project (File | New | Other… then select Database).
RESTServer4

 

 

 

 

 

 

 

– Add a TppReport, TrbReportDirectory, and TrbRestReportProvider to the DataModule.
RESTServer5

 

 

 

 

 

– Assign the Report and Directory properties of the TrbRestReportProvider component.
RESTServer6

 

 

 

 

 

– Define the DirectoryName and FileDirectory properties of the TrbReportDirectory component. The DirectoryName property is the name shown in the client, the FileDirectory property is the location on disk that the reports are located.

RESTServer7

 

 

 

 

 

– Register the datamodule with the REST Report Provider Factory in the initialization section using similar code: (The second parameter of the RegisterModule routine should be the DirectoryName)

initialization

TrbRestReportProviderFactory.RegisterModule(TDataModule, 'ReportFiles');

finalization

TrbRestReportProviderFactory.UnRegisterModule('ReportFiles');

Note: If the reports need data access, this datamodule is an ideal location for the delphi DB components.

 

4. Save, build, and run the server. Click Start to begin.
RESTServer8