DelphiLearn PythonPythonPython GUIRAD Studio

Easily Integrate A Flexible Python REST Client To RAD Server In Python Windows GUI App Built In Delphi

blogbanner3-20

REST (REpresentational State Transfer) has emerged as the standard architectural design for web services and web APIs in these days.

This article will show you how easy it is to integrate a REST API Clients to RAD Server using Python and run it in the Python GUI by Python4Delphi with RAD Studio and gets the results.

Prerequisites: Before we begin to work, download and install the latest Python for your platform. Follow the Python4Delphi installation instructions mentioned here. Alternatively, you can check out the easy instructions found in this video Getting started with Python4Delphi.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

0_rundemo1-3785324
Open Demo01.dproj

 

1. Setup RAD Server

If this is your first time configuring RAD Server, you can follow this tutorial. If you successfully configure the RAD Server, an Information wizard appears with the files created and the data added to the database. Click OK:

2_3_leftemsempty-2441776
Information Wizard will Appear if the Configurations are Success.

In RAD Development Server, you will get the following log:

3_3connected_radserver-5909489
Rad Development Server Version 4.2.

And you can also test the connection, by clicking to “Open Browser”:

3_1connected_browser-9274829
RAD Server are Connected to Your Browser.

Or “Open Console”:

3_2connected_console-2888625
RAD Server are Connected to Your Console.

Congratulations! You are successfully configuring the RAD Server!

 

2. Access the Server via Python request Module

How do we interact with REST API Clients? In Python 3, we are lucky to have an excellent HTTP library: Kenneth Reitz’ requests. It’s one of the few most powerful projects worth treating as if it is part of the Python’s standard library.

First, let’s install it using easy install:

Installation progress in Windows Command Prompt:

1_1-8707015
pip install request in Windows Command Prompt.

The installation is completed! Let’s test the installation by running this simple GET request to RAD Server using project Demo1 from Python4Delphi with RAD Studio. :

Output:

3_4connectusing_python4delphi-7323278
You are Connected! This is an OK Status Code (200) from RAD Server.

Request returns а Response, a powerful object for inspecting the results of the request. Using Response, we can examine the headers and contents of the response, get a dictionary with data in JSON format as the response, and also determine how successful our access to the server was by the response code from it.

In our example above, the response code was 200, which means that the request was successful!

In total, there are four main types of actions in Request Methods:

  • GET: Retrieve information (works like the search results). This is the most common type of request. Using it, we can get or select the data we are interested in from those that the API is ready to share.
  • POST: Adds new data to the server. Using this type of request, we can, for example; add a new item to your inventory or database.
  • PUT: Changes existing information. For example, using this type of request, it would be possible to change the color or value of an existing product or data.
  • DELETE: Deletes existing information.

 

Congratulations, you have successfully integrate Python REST API Client to RAD Server in Python GUI for Delphi Windows App! See you in our next tutorials!

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

close
Related posts
Learn PythonPythonPython GUIVideos

Learn Python With Master the Basics of Tkinter - Full Tkinter Programming Course Video

DelphiPythonPython GUIWindows

Learn To Build A Python GUI For Manipulating Date, Time, And Timestamps Using Arrow Library In A Delphi Windows App

DelphiDelphiVCLPythonPython GUIWindows

Fill Solid Shapes With .Brush

DelphiDelphiVCLPythonPython GUIWindows

Create A Drawing Space Using DelphiVCL.Canvas

Leave a Reply

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

en_USEnglish