DelphiLearn PythonPythonPython GUIRAD Studio

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

woman wearing red and black checkered blouse using macbook

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:

1_0-8421956

 

2. Creating the Project

Open your RAD Studio and create a new project:

  • For Delphi, choose File > New > Multi-Device Application – Delphi > Blank Application.
1_1-7024310

 

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)

1_3-5595983

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

1_4-9895163
  • 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.
1_5-8859422

 

4. Connecting to Python Flask Server

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

1_2-5196181

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.

 

close
Related posts
Learn PythonPythonPython GUIVideos

Learn Python With Transitioning From Developing Software to Developing People by Matthew Knapp Bachman (PyCon 2020) Video

DelphiDelphiVCLLearn PythonPythonPython GUIWindows

Decipher the DelphiVCL.Application

DelphiDelphiVCLLearn PythonPythonPython GUIWindows

Create a Very Basic Empty Form using DelphiVCL.Form

DelphiDelphiVCLLearn PythonPythonPython GUIWindows

An Introduction To DelphiVCL: A Python GUI Builder For Windows

Leave a Reply

Your email address will not be published. Required fields are marked *

en_USEnglish