Easily Create A Flexible Python REST Server In A Delphi Windows GUI App
February 9, 2021 By Muhammad Azizul
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 create a RESTful web service using Python and the Flask microframework in Python4Delphi with RAD Studio and gets the results.
Prerequisites: Before we begin to work, download and install the latest Для просмотра ссылки Войдиили Зарегистрируйся for your platform. Follow the Для просмотра ссылки Войди или Зарегистрируйся installation instructions mentioned Для просмотра ссылки Войди или Зарегистрируйся. Alternatively, you can check out the easy instructions found in this video Для просмотра ссылки Войди или Зарегистрируйся.
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 Для просмотра ссылки Войдиили Зарегистрируйся. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this Для просмотра ссылки Войди или Зарегистрируйся.

Open Demo01.dproj
Central to the concept of RESTful web services is the notion of resources. Resources are represented by Uniform Resource Identifier or URIs. The clients send requests to these URIs using the methods defined by the HTTP protocol, and possibly as a result of that the state of the affected resource changes.
The HTTP request methods are typically designed to affect a given resource in standard ways:
The REST design does not require a specific format for the data provided with the requests. In general data is provided in the request body as a JSON blob, or sometimes as arguments in the query string portion of the URL.
Installation progress in Windows Command Prompt:

pip install flask in Windows Command Prompt.
Now open up the Demo01 VCL and copy-paste these code:
Output in Python GUI:

Result in browser:

Congratulations! You have integrated what “seems complicated concept” Python REST Server with Delphi, using Python4Delphi.
Для просмотра ссылки Войдиили Зарегистрируйся
February 9, 2021 By Muhammad Azizul
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 create a RESTful web service using Python and the Flask microframework in Python4Delphi with RAD Studio and gets the results.
Prerequisites: Before we begin to work, download and install the latest Для просмотра ссылки Войди
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 Для просмотра ссылки Войди

Open Demo01.dproj
1. What is REST System?
The REST system is defined by these six characteristics as its design rules:- Client-Server: There should be a separation between the server that offers a service, and the client that consumes it.
- Stateless: Each request from a client must contain all the information required by the server to carry out the request. In other words, the server cannot store information provided by the client in one request and use it in another request.
- Cacheable: The server must indicate to the client if requests can be cached or not.
- Layered System: Communication between a client and a server should be standardized in such a way that allows intermediaries to respond to requests instead of the end server, without the client having to do anything different.
- Uniform Interface: The method of communication between a client and a server must be uniform.
- Code on demand: Servers can provide executable code or scripts for clients to execute in their context. This constraint is the only one that is optional.
2. Introduction to RESTful Web Service
The REST architecture was originally designed to fit the HTTP protocol that the world wide web uses.Central to the concept of RESTful web services is the notion of resources. Resources are represented by Uniform Resource Identifier or URIs. The clients send requests to these URIs using the methods defined by the HTTP protocol, and possibly as a result of that the state of the affected resource changes.
The HTTP request methods are typically designed to affect a given resource in standard ways:
HTTP Method | Action | Examples |
---|---|---|
GET | Obtain information about a resource | Для просмотра ссылки Войди |
GET | Obtain information about a resource | Для просмотра ссылки Войди |
POST | Create a new resource | Для просмотра ссылки Войди |
PUT | Update a resource | Для просмотра ссылки Войди |
DELETE | Delete a resource | Для просмотра ссылки Войди |
3. A Simple Flask API GET Request
Firstly, make sure you have Flask installed. It’s easiest to use Python package manager, pip or easy install:
Код:
pip install flask

pip install flask in Windows Command Prompt.
Now open up the Demo01 VCL and copy-paste these code:
Python:
from flask import Flask, json
companies = [{"id": 1, "name": "Embarcadero Technologies"}, {"id": 2, "name": "python.org"}]
api = Flask(__name__)
@api.route('/companies', methods=['GET'])
def get_companies():
return json.dumps(companies)
if __name__ == '__main__':
api.run()

Result in browser:

Congratulations! You have integrated what “seems complicated concept” Python REST Server with Delphi, using Python4Delphi.
Для просмотра ссылки Войди