Site icon Python GUI

Tutorial: Using The Delphi REST Client To Access Python REST Server (Flask)

woman wearing red and black checkered blouse using macbook

Photo by Christina Morillo on Pexels.com

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:

[crayon-662c31f1229c5205114680/]

This is how it looks like in the command prompt:

 

2. Creating the Project

Open your RAD Studio and create a new project:

 

3. Adding the REST Components

  1. Drop the TRESTClient, TRESTRequest, and TRESTResponse components on the form.

2. In the Object Inspector, set the BaseURL property of the TRESTClient to http://127.0.0.1:5000 (your Flask’s server)

3. Select the TRESTRequest component on the form and set the following properties:

 

4. Connecting to Python Flask Server

Right-click the TRESTRequest component and select Execute. If you are connected successfully, this window will shows up:

Congratulations! You have integrated what “seems complicated concept” Python REST Server with Delphi, using Delphi’s REST Client.

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.

 

Exit mobile version