Python API for WebFramework
Project description
C++ HTTP/HTTPS server with Python API
Quick start
Server needs few files to run:
- web.json with routes
- Executors
- config.json with server settings
All these files must be in the same directory asmain.py
main.py
from web_framework_api.WebFramework import WebFramework # Server
from web_framework_api.utility.DLLHandler import initialize_web_framework # WebFramework initialization
from web_framework_api.exceptions.WebFrameworkException import WebFrameworkException # Exception
def on_start():
print("Server is running")
if __name__ == '__main__':
try:
initialize_web_framework() # Load WebFramework shared library
server = WebFramework.from_path("config.json") # Create server
server.start(True, on_start) # Start server and wait
except WebFrameworkException as exception:
print(exception)
exit(-1)
Settings
web.json
{
"HelloExecutor": {
"route": "",
"loadType": "initialization"
}
}
Config
config.json
{
"WebServer": {
"ip": "0.0.0.0",
"port": 8080,
"timeout": 0
},
"WebFramework": {
"settingsPaths": [
"web.json"
],
"loadSources": [
"hello_executor"
],
"assetsPath": "assets",
"templatesPath": "templates",
"cachingSize": 536870912,
"webServerType": "multiThreaded",
"HTTPS": {
"useHTTPS": false,
"pathToCertificate": "certificates/cert.pem",
"pathToKey": "certificates/key.pem"
},
"defaultAssetsPath": "WebFrameworkAssets"
},
"Logging": {
"usingLogging": false,
"dateFormat": "DMY",
"logFileSize": 134217728
},
"ThreadPoolServer": {
"threadCount": 0
}
}
Run sample
After running server open url 127.0.0.1:8080.
You will see response from server
{
"message": "Hello, World!"
}
Executors
Executors are C++ classes that responsible for giving responses for their route(url).
Source code of HelloExecutor from example
HelloExecutor.h
#pragma once
#include "Executors/BaseStatelessExecutor.h"
namespace executors
{
class HelloExecutor : public framework::BaseStatelessExecutor
{
public:
HelloExecutor() = default;
void doGet(framework::HTTPRequest& request, framework::HTTPResponse& response) override;
~HelloExecutor() = default;
};
}
HelloExecutor.cpp
#include "HelloExecutor.h"
#include "JSONBuilder.h"
namespace executors
{
void HelloExecutor::doGet(framework::HTTPRequest& request, framework::HTTPResponse& response)
{
response.addBody(json::JSONBuilder(CP_UTF8).appendString("message", "Hello, World!"));
}
DECLARE_EXECUTOR(HelloExecutor);
}
More information you can find in wiki.
Hello executor
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file web_framework_api-1.0.5.tar.gz
.
File metadata
- Download URL: web_framework_api-1.0.5.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf1fd6e7a9c4666566eef8a84f39f9823147d211829c9dd607ace7173cdd9380 |
|
MD5 | 5432fcd507c8af5b56bc231a4b47c404 |
|
BLAKE2b-256 | 0a5c1e7fce38f017fd7071d6eec95448a9127b3170d6e5f17671e20101bef2f2 |
File details
Details for the file web_framework_api-1.0.5-py2.py3-none-any.whl
.
File metadata
- Download URL: web_framework_api-1.0.5-py2.py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e237459fb172efd606a3af489ceaf2b10a0d23c233d909e5507d36887528e44e |
|
MD5 | 4b2d5ffa85bda4857b901a907fa94a84 |
|
BLAKE2b-256 | d293d4f124742cf6b5a83077cbdd4194735694c9e546f057959e2e58a3c2b340 |