REST (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs in these recent years.
This post will demonstrate how easy it is to use the Delphi REST Client Library to access Python REST Server (Flask microframework).
Prerequisites: If this is your first time to set up Delphi’s REST Client Library in RAD Studio for accessing any REST-based web services, you can read this article to set them up. But, there are several differences in configurations for accessing Flask’s Python REST server. This article will show you the details about it. Also, you can read this tutorial to set up your first Python Flask REST Server.
1. Turn-On your Flask Server
Turn on your Flask server, by navigating to your project’s path, and run this command:
This is how it looks like in the command prompt:
2. Creating the Project
Open your RAD Studio and create a new project:
- For Delphi, choose File > New > Multi-Device Application – Delphi > Blank Application.
3. Adding the REST Components
3. Select the TRESTRequest component on the form and set the following properties:
- In the Structure View, expand the Params node.
- Right-click the Params node, and click Add item on the context menu.
- Under Params, click the newly added parameter 0-.
- In the Object Inspector, set the parameter name to id, and the parameter value to 1.
4. Connecting to Python Flask Server
Congratulations! You have integrated what “seems complicated concept” Python REST Server with Delphi, using Delphi’s REST Client.