A simple-to-use framework for http and https servers
Project description
🌐 HttPython
A simple-to-use http and https server, simillar to flask, in python.
✅ To-do
- HTTP and HTTPS server class
- Request class
- Document class
- Python code execution in html
- MIME type in Document class
- Default headers per server
- Per host handler
❓ How to use
from httpython.servers import HTTP_Server
from httpython import RequestMethod
# Define the port and host
host, port = "127.0.0.1", 80
# Instanciate the server object
server = HTTP_Server(host, port)
#For HTTPS servers, use HTTPS_Server(host, port, certificate_path, private_key_path)
# Create an handler for requests
@server.method(RequestMethod.GET, route="*", host="*") # Using the route and host parameters as '*' will use this handler as a fallback for the GET method.
def GET_Handler(request):
# do stuff
return Request.response(
500, # Status code
"Not Implemented", # Message
{"Server": "httpy/2.0", "Connection": "closed"}, # Headers
b"" # Body
)
@server.method(RequestMethod.GET, route="/api/", host="*")
def API_Handler(request):
# do stuff
return Request.response(
500, # Status code
"Not Implemented", # Message
{"Server": "httpy/2.0", "Connection": "closed"}, # Headers
b'{"foo": "bar"}' # Body
)
# Run the server
server.run()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
httpython-0.2.6.tar.gz
(5.3 kB
view hashes)
Built Distribution
Close
Hashes for httpython-0.2.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4136cddb4da97021977784352d3e44e9a1e9954fe3bbb1056ad3851b4dd87119 |
|
MD5 | cdb84a707a825ade48046c6e47a3d50a |
|
BLAKE2b-256 | 8882f744db41f32ccecb6b00d12760ac66485dca2e31b9c5464d57ee8d305b74 |