Reader small image

You're reading from  Expert Delphi - Second Edition

Product typeBook
Published inFeb 2024
Reading LevelExpert
PublisherPackt
ISBN-139781805121107
Edition2nd Edition
Languages
Right arrow
Authors (2):
Marco Cantù
Marco Cantù
author image
Marco Cantù

Marco Cantù is an experienced Delphi expert, who started working with the product since its introduction in 1995. He is currently working as a Product Manager for RAD Studio at Embarcadero Technologies, an Idera company. Prior to that, Marco was a Delphi trainer and consultant for Wintech Italia. Over the years, Marco has written 20 books on Delphi, from the classic Mastering Delphi series to the recent Object Pascal Handbook. Marco has been a speaker at many Delphi and programming conferences worldwide, including over 10 Borland US Conferences, the Software Development Conference, Borland European conferences, EKON (Germany), DCon (UK), Conference to the Max (Holland), DelphiTage, the Italian Delphi Day, and a few editions of Delphi Developer Days. Marco is based in Italy.
Read more about Marco Cantù

Paweł Głowacki
Paweł Głowacki
author image
Paweł Głowacki

Paweł Głowacki was Embarcadero's European Technical Lead for Developer Tools. Previously, Paweł spent over 7 years working as a senior consultant and trainer for Delphi within Borland Education Services and CodeGear. Apart from working with Embarcadero customers across the region, he represented Embarcadero internationally as a conference and seminar speaker. Paweł passed away in mid-December 2017, but he is alive in the hearts of the Delphi developers community, worldwide.
Read more about Paweł Głowacki

View More author details
Right arrow

Easy REST API Publishing with RAD Server

Looking at the different options available for Delphi, the most feature-rich and powerful architecture for building mobile backends is RAD Server. Unlike other types of Delphi server applications, RAD Server is pre-built and includes core features out of the box.

In this chapter, we’ll introduce the key elements of RAD Server, without going too deep into all of the features, as the features themselves would take an entire book. This is what we are going to cover:

  • RAD Server setup
  • Building RAD Server resources
  • The ToDo list in RAD Server
  • Creating a client app for RAD Server

The goal of this chapter is to introduce you to RAD Server and explain its core features and how you can write your own web service endpoints and call them in a client app. Of course, we’ll do this by building practical demos as we usually do in this book.

Technical requirements

RAD Server is installed as part of Delphi Enterprise or Architect. RAD Server is designed as a scalable REST API publishing framework. Its functionality is extended through building Delphi BPL packages that are loaded into the RAD Server at its startup. It also requires access to the Embarcadero InterBase SQL database, where it keeps its system database. During the installation of Delphi, make sure to install the development version of InterBase. It comes with a special license for using it as a system database for RAD Server.

To summarize, the RAD Server support is available only in the Enterprise and Architect versions of the product, not in the Professional and Community editions.

The source code of the demos in this chapter can be found on GitHub at the following link: https://github.com/PacktPublishing/Expert-Delphi_Second-edition

RAD Server setup

As a starting point, make sure that InterBase is installed and running on your system. In the Windows Start menu, locate and run InterBase Server Manager. You can see the window of this utility app in Figure 13.1. If the server does not start, then run it. In the default installation, the InterBase instance name is gds_db. The name of the database instance will be needed during the RAD Server setup.

Figure 13.1: The InterBase Server Manager

Figure 13.1: The InterBase Server Manager

Now go to the Windows command line and enter the EMSDevServer command. The Delphi bin directory is in the path after the installation, so RAD Server should start.

Note

Note that in many places you will see the word EMS when referring to RAD Server. It stands for Enterprise Mobility Services and it is the former name of RAD Server.

The very first time EMSDevServer is run, or when it is run with the -setup parameter, you will see the installation wizard (see Figure 13.2), which will create a...

Building RAD Server resources

The RAD Server architecture has been elegantly designed. You can add custom REST API resources through Delphi package library files that are loaded to RAD Server at its startup. The location of packages to be loaded is stored in the ini configuration file.

In the last chapter, we used the Web Broker architecture to expose CRUDL operations on the underlying ToDo data stored in the SQLite database as custom REST APIs. Here, we are going to implement a similar solution, but in this case, we are going to expose the same functionality using RAD Server. Initially, we are going to leverage the advanced features of RAD Server including its automatic mapping to database operations. Later on, we’ll go back to the architecture we built in previous chapters and expose the IToDoData interfaces, following the same process we used in the last chapter with Web Broker.

Open the New Items dialog from the Delphi File menu. Select the RAD Server category and...

The ToDo list in RAD Server

Let’s now move to the implementation of a ToDo list server based on the architecture of the previous chapters, rather than directly exposing the database. Notice that there is nothing wrong with the approach we used in the previous section, but it’s good to get a bit deeper to better understand how RAD Server works:

  1. Let’s start by creating a proper folder structure for our projects. Create a new folder for RAD Server ToDo resource and client projects. Inside this folder, create three sub-folders: resource, client, and shared.
  2. Now, run the RAD Server wizard again. On the second page of the wizard, this time we can just pick a unit and use the resource name todo.
  3. On the third page, this time we want to pick the endpoints of the wizard (see Figure 13.8, again). Select Sample EndPoints and all five sub-elements These endpoints will translate to different HTTP request types and URLs. We want all of them because there are five...

Creating a client app for RAD Server

Let’s now create a client application for the REST API we just built with RAD Server. We’ll do this by reusing the UI and some of the code from the previous versions:

  1. Create a new, blank multi-device project and save it as ToDoListEMS in the client folder.
  2. Keep the default name of the main form. It does not matter because in a moment we are going to remove it from the project.
  3. Add to the project the uToDoTypes and uToDoUtils units.
  4. Add a new data module to the client project. Save it as uDMToDoEMS and change its Name property to DMToDoEMS.
  5. Add uToDoTypes to its uses clause in the interface section and copy the five IToDoData interface method declarations from the uToDoTypes unit to the public section of the data module. The class should look like this:
    type
      TDMToDoEMS = class(TDataModule, IToDoData)
      private
        { Private declarations }
      public
      ...

Summary

In this chapter, we have seen how to use RAD Server to build multi-tier architectures and provide a lot of reusable functionality to build great mobile backends for your cross-platform, mobile Delphi apps.

As Delphi’s RAD technology and FireMonkey make you fast at building the UI of an app, compared to other development tools, RAD Server makes you fast at building and publishing web services and the backend of your mobile and desktop applications. This chapter offered only an introduction to RAD Server, as it is a very complex technology with many built-in features.

The next chapter will change focus; we will be getting back to mobile and focusing on the final steps of mobile development: deployment to app stores.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Expert Delphi - Second Edition
Published in: Feb 2024Publisher: PacktISBN-13: 9781805121107
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Marco Cantù

Marco Cantù is an experienced Delphi expert, who started working with the product since its introduction in 1995. He is currently working as a Product Manager for RAD Studio at Embarcadero Technologies, an Idera company. Prior to that, Marco was a Delphi trainer and consultant for Wintech Italia. Over the years, Marco has written 20 books on Delphi, from the classic Mastering Delphi series to the recent Object Pascal Handbook. Marco has been a speaker at many Delphi and programming conferences worldwide, including over 10 Borland US Conferences, the Software Development Conference, Borland European conferences, EKON (Germany), DCon (UK), Conference to the Max (Holland), DelphiTage, the Italian Delphi Day, and a few editions of Delphi Developer Days. Marco is based in Italy.
Read more about Marco Cantù

author image
Paweł Głowacki

Paweł Głowacki was Embarcadero's European Technical Lead for Developer Tools. Previously, Paweł spent over 7 years working as a senior consultant and trainer for Delphi within Borland Education Services and CodeGear. Apart from working with Embarcadero customers across the region, he represented Embarcadero internationally as a conference and seminar speaker. Paweł passed away in mid-December 2017, but he is alive in the hearts of the Delphi developers community, worldwide.
Read more about Paweł Głowacki