Site icon Python GUI

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.

Open Demo01dproj

 

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:

Information Wizard will Appear if the Configurations are Success

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

Rad Development Server Version 42

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

RAD Server are Connected to Your Browser

Or “Open Console”:

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:

[crayon-6606a4699c5ae013613547/]

Installation progress in Windows Command Prompt:

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. :

[crayon-6606a4699c5d2292782094/]

Output:

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:

 

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.

Exit mobile version