-
Notifications
You must be signed in to change notification settings - Fork 3
WSGI Integration
Dawid Kraczkowski edited this page Jan 26, 2022
·
4 revisions
Fast And Ultra-Lightweight HTTP/1.1 WSGI Server, if you haven't heard about it, I highly recommend to check it out.
Keep in mind
bjoern
relies onlibev-dev
, make sure it is installed and avaialable in your system. More information about bjoern and libev can be found here.
main.py
import chocs
app = chocs.Application()
@app.get("/hello/{name}")
def hello(request: chocs.HttpRequest) -> chocs.HttpResponse:
return HttpResponse(body=f"Hello {request.path_parameters['name']}!")
chocs.serve(app)
To run application with bjoern package, the following function can be used
chocs.serve
(app
: chocs.Application
, host
: str
= "127.0.0.1"
, port
:int
= 80
, debug
: bool
= False
)
-
app
argument should point to your application -
host
defines your host by default it is your localhost -
port
defined port on which server will listen for connections -
debug
turns on or off detailed error messages in the logs
This tutorial will use Gunicorn as example server, this tutorial also assumes you have installed on your local machine:
- poetry
- python 3.7 or greater
poetry init
Follow the creator steps when asked for defining main dependencies answer no
, same for interactively defining dependencies and confirm generation.
poetry add chocs
poetry add gunicorn
main.py
import chocs
http = chocs.Application()
@http.get("/hello/{name}")
def hello(request: chocs.HttpRequest) -> chocs.HttpResponse:
return chocs.HttpResponse(f"Hello {request.path_parameters.get('name')}!")
app = chocs.create_wsgi_handler(http, debug=False)
poetry shell
gunicorn main:app
- Creating new application
- Registering a controller
- Grouping controllers
- Registering middleware
- Dynamically loading modules
TBA
TBA
- Reading request's body
- Accessing request's parsed body
- Accessing request's headers
- Accessing path's parameters
- Reading client cookies
- Comparing requests objects
- API