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

Building Mobile Backends

In the mobile development world, it is common to have dedicated developers and teams responsible for just building mobile frontends (the actual app running on the device) and backends (web services for accessing data and hosting some of the business logic). For this reason, we also want to wear the backend developer hat and use Delphi to build modern, scalable, secure, fault-tolerant REST API web services with full database access. This chapter will cover the following points:

  • Delphi and multi-tier architectures
  • Working at a low level with WebBroker
  • Do-it-yourself with DataSnap

The objective of this chapter is to get you to understand the different choices for backend technologies in Delphi and gain practical knowledge on how to build web services. There is one further web service technology in Delphi called RAD Server, which will be the topic of the next chapter.

Technical requirements

As usual, all of the libraries covered in this chapter ship in Delphi, and most of them have been available for many releases. The DataSnap support, however, is available only in the Enterprise version 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

Delphi and multi-tier architectures

In the previous chapter, we saw that you can use web services and cloud-hosted web APIs to create an information system where apps running on different devices can connect to the same data store. Not only you can use Delphi to integrate with existing web services, but you can also build your own.

Why would you build mobile backend services? Multi-tier architectures have a lot of benefits. But what exactly is a multi-tier solution? It’s an architecture in which client apps communicate with server apps to access underlying resources. Compared to a client/server application, which has the user interface (UI), the business logic, and the database access all combined (even if possibly logically divided into different modules, as we did for the todo app in Chapter 10), in a multi-tier scenario where the database access lives on the server, along the core of the business logic, the client app has only the UI and the limited business logic required...

Working at a low level with WebBroker

The most simple and generic web server development framework in Delphi is WebBroker. It is the underlying technology for many specialized web service types that you can build with Delphi, such as SOAP XML web services, DataSnap, and RAD Server. If you create a new web server app with the New WebBroker App wizard, you can implement arbitrary HTTP server functionality. In our case, that will be a simple web service that will provide REST API access to a new version of the Todo application.

Here are the steps to start building our first WebBroker server application:

  1. Click on File | New | Other in the IDE and double-click on the Web Server Application wizard in the Web category.
  2. On the first page of the wizard, titled Platform, you have the option to indicate the target platforms. Windows is required, and you can add Linux if you want. I recommend enabling it if your version of Delphi supports it.
  3. On the second page of the wizard...

Do-it-yourself with DataSnap

WebBroker is good for a basic level HTTP server functionality, but the more complex the system you want to build, the more you look into complete Delphi multi-tier frameworks such as DataSnap (covered in this section) or RAD Server (covered in the next chapter). They provide a lot more high-level functionality than you can find in WebBroker. However, notice that the higher-level multi-tier solutions are available only in the Enterprise and Architect versions of Delphi, not in the Professional and Community Editions.

The DataSnap framework has been part of Delphi since its early days and has evolved over that time. Delphi 3 introduced the MIDAS technology to make it easy to build client/server database applications. In Delphi 6, this technology has been renamed to DataSnap, and in Delphi 2009, it has been completely rewritten. In this new architecture, remote methods published by a DataSnap server looked like database-stored procedures that a typical...

Summary

In this chapter, we have seen different options for building mobile backends with Delphi. There are many wizards to help you build all kinds of server apps, including simple WebBroker HTTP servers, SOAP XML web services, and DataSnap.

The DataSnap architecture was great when it was built, but it was never meant to be a backend for modern REST-style APIs. In fact, it started in the COM world and was extended to embrace HTTP.

If you want to fully embrace the REST model, creating a stateless and scalable architecture, with more ready-to-use out-of-the-box services, you might want to move to a new architecture Embarcadero added to Delphi, which is called RAD Server. This is covered in detail in the next chapter. RAD Server offers the best and most extensive solution as a backend for your mobile applications.

The next chapter will guide you in building a RAD Server web service and the matching client application, migrating our ToDo demo to this new technology, in a couple...

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 €14.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