Bayesean Blog - Desktop, Mobile and IOT Developer Blog


PHP REST Server and Delphi Client Intro

Posted on 30th Jul 2017 in Delphi FMX, Delphi VCL


restserver.png

This is an updated five part series using PHP REST server with SLIM and Delphi VCL / FMX using both Indy Components and the newer REST components shipped with the Latest IDE. All processes use JSON to package the data to be sent and received.

If you are new to this, then you will be able to gain understanding on how it set up a REST App by following this 5 part series. More advanced processing using various Authorisations are implemented in the latter parts.

Lastly I have provided some background to REST, RESTAPI and JSON.

Feel free to read below a summary of each part or click on a link below to access one of the parts of the REST Series or scroll down to find out What REST is about?

Visit Part 1    - PHP PDO REST Server Part 1 - Slim Backend Webserver

Visit Part 2A - Delphi Basic CRUD REST Client– Indy Components with JSON

Visit Part 2B - Delphi REST VCL Client Basic Authorization and APIKey Authorization

Visit Part 3  - Delphi VCL REST Client Application using Indy and SuperObject.

Visit Part 4 - Delphi FMX REST Client Application using the latest REST Components

Visit Part 5  - PHP SLIM REST Server and Delphi VCL /Delphi FMX using 3 x Authorization methods.

 

Part 1 - PHP PDO REST Server Part 1 - Slim Backend Webserver.  Visit the Blog

This covers the important steps to setup an effective PHP backend REST-Server using the lightweight Slim Rest Framework using Middleware with implemented routes. Whilst no Authorisation is implemented, the basic implementation steps are followed.

Part 2A- Delphi Basic CRUD REST Client– Indy Components with JSON-Visit the Blog

This uses Delphi VCL and the standard Indy Components shipped with the IDE. To implement JSON into the application, the excellent high quality Delphi SuperObject JSON library is used to send and receive RESTful calls to the Webserver and back. If you have an older IDE without the latest REST Components, then this Blog is for you to understand how to implement INDY and SuperObject.  

Download the free to download REST Debugger from Embarcadero to test your REST Calls before implementation.

Part 2B - Delphi REST VCL Client Basic Auth Part 2B -  Visit the blog

This is a follow on from Part 2A that demonstrated how you can add authorization to the code.  Visit Part 2A.

Sending data across the internet is not secure by nature. The Rest Server will need to be secured and this depends on the nature of the data that is being stored. Here are two Authorization methods provided as snippets:-

  • Basic Authorization using Indy Components.
  • APIKey authorization using Indy Components.

Basic Authorization is the bare minimum however using APIKey Authorization ensures that the correct app is sending or receiving data. Yes you can combine both by forcing the Basic Authorization layer to authorize and once accepted then authorize the APIKey before transacting data. Visit the blog to find out more…

Part 3 – Delphi VCL REST Pricing Client App Part 3 – Visit Blog

This is a simple VCL Sales Price List that uses CRUD (create, read, update and delete) RESTful calls. The purpose of the app is to bio-directionally synchronise the base application and the Website’s Sales Price List.

This will demonstrate the basics of how to implement this and makes us of the Client Dataset

Component. To make it easier it simulates a database so the code should work out of the box.

It must be noted that this is a proof of concept and will need finer work before being production ready. If you are using a recent IDE then have a look at Part 4.

 Part 4 - Delphi FMX REST Client App Part 4.  Visit the Blog

This demonstrates a revision of the VCL Delphi Sales Price List Client Application upgraded to the latest IDE 10.2.3. Embarcadero has made enormous progress to provide powerful REST components and JSON Libraries with the ideal FIREDAC implementation.

Part 5 - PHP SLIM RESTServer &Delphi Auth. Visit the Blog

This is a two part blog which covers a lot of information. It deals in three authorization types :- Basic Authorization, APIKey Authorization and JWT Authorization methods

This is a long blog and the first part covers the PHP RESTServer side.

The second part covers the RESTClient which is also split into Delphi VCL REST Client implementation and Delphi FMX REST Client implementation.

REST Services what is it all About?

General Background

REST (Representational State Transfer) has become the standard design architecture for developing Web APIs.

REST is a stateless client-server relationship which means that unlike many other approaches there is no client context being stored server side.

No Sessions are required as each request contains all the information necessary for the server to authenticate the user and if authenticated then sends and receives data as per pre-determined calls to a set of HTTP URI endpoints.

REST takes advantage of the HTTP request methods to layer itself into the existing HTTP architecture.

These operations consist of the following:

GET - Used for basic read requests to the server.

PUT- Used to modify an existing object on the server.

POST- Used to create a new object on the server.

DELETE - Used to remove an object on the server.

 

By creating URI endpoints that utilize these operations, a RESTful API is quickly assembled.

The Rest API

In this sense the API stands for Application Programming Interface which allows for publicly exposed methods for an application to be accessed and manipulated outside of the program itself.

A common usage of an API is when you wish to obtain data from an application without having to actually visit the application Front end.

To allow this action to take place, the application will provide a published API that specifically allows for dissimilar applications to make calls to its data and return this data to the user from inside a Webserver. The REST API accesses the Database directly and will pass through specific information per each RESTful endpoint that is set up.

Example:-

yourdomain.com/api/v1/pricing/all

JSON

JSON stands for JavaScript Object Notation and is a lightweight data-interchange format.

It is easily read as it is closer to text in nature verses XML and can be read on any text editor. Being lightweight, it is easy for machines to parse and generate and it is quick to transfer over slower internet connections.

Mobile phones are interfacing with the cloud regularly and band-width is a premium so the need for lightweight data such as JSON meets this requirement.

Whilst it is based on a subset of the JavaScript Programming Language, these days most languages can parse and generate data into JSON and it is fast becoming the preferred developer format for data- interchange.

Summary

If you were new to RESTful  processes and JSON, you now have a simplified understanding of what REST is all about. Select one of the five Part Series above to understand how to work with the RESTful components.

All code is under the MIT Licence and can be found in the Bayesean-Blog Github Repository  and is easily downloadable at the end of each blog.

 

Happy Coding


Be the First to Comment...

Add a Comment

9+5

Recent News

Delphi A Professional VCL DBGrid Part Four
Delphi A Professional VCL DBGrid Part Three
Delphi A Professional VCL DBGrid Part Two
Delphi A Professional VCL DBGrid Part One
Delphi VCL Buttons in DBGrid
Two Helper Apps for Delphi LibUSB
Delphi Libusb Library Introduction
Delphi Object directly to a Json string in a REST Client

Categories

Bootstrap 4
Delphi VCL
Delphi FMX
Ajax
Bootstrap 3
CSS
XE4>Delphi > XE4
Delphi < XE4
PHP

Archives

June 2019

Delphi A Professional VCL DBGrid Part Four

May 2019

Delphi A Professional VCL DBGrid Part Three

April 2019

Delphi A Professional VCL DBGrid Part Two

March 2019

Delphi A Professional VCL DBGrid Part One

November 2018

Delphi VCL Buttons in DBGrid

October 2018

Two Helper Apps for Delphi LibUSB

September 2018

Delphi Libusb Library Introduction

August 2018

Delphi Object directly to a Json string in a REST Client
Delphi using Environment Variables in your App

July 2018

Delphi FMX Leaflet Plotter using OSM Maps

June 2018

C2PAS32 Convertor Application
C to Delphi Open Source Convertors Shootout
Delphi command-line programs with DOSCommand

May 2018

Delphi PDF Embedded viewer with PDF.js

March 2018

Delphi FMX - Changing TCharacter to TCharHelper
Make Your Delphi App POP using Javascript!

January 2018

Delphi FMX Dashboard using Chart.JS
Delphi FMX Form Docking

December 2017

PHP Slim REST Server & Delphi Auth Part 5

November 2017

Delphi FMX REST Client App Part 4

October 2017

Delphi VCL REST Pricing Client App Part 3

September 2017

Delphi REST VCL Client Basic Auth Part 2B

August 2017

Delphi REST Client Part 2A
PHP PDO REST Server Part 1

July 2017

PHP REST Server and Delphi Client Intro

June 2017

Delphi SQLite Encryptor-Decryptor Tool
Updating Applications Manifest using Delphi

May 2017

Create a Visual IP Address Geolocation with PHP

March 2017

PHP Downloader using Countdown timer
PHP File Downloader from a Inbox Selection

February 2017

Javascript Image-File Uploader with ThumbViewer

January 2017

Morris Charts and PHP-PDO

December 2016

CSS to create a functional Toggle Button