A microframework
Project description
Rouver
A microframework for Python 3, based on werkzeug.
Routing
>>> from rouver.router import Router
>>> from rouver.response import respond_with_html, respond_with_json
>>> def get_index(environ, start_response):
... return respond_with_html(start_response, "<div>Foo</div>")
>>> def get_count(environ, start_response):
... return respond_with_json(start_response, {"count": 42})
>>> router = Router()
>>> router.add_routes([
... ("", "GET", get_index),
... ("count", "GET", get_count),
... ])
Routes with placeholders:
>>> def get_addition(environ, start_response):
... num1, num2 = path
... return response_with_json(start_response, {"result": num1 + num2})
>>> def numeric_arg(request, path, value):
... return int(value)
>>> router.add_template_handler("numeric", numeric_arg)
>>> router.add_routes([
... ("add/{numeric}/{numeric}", "GET", get_addition),
... ])
Routes with wildcards:
>>> def get_wildcard(environ, start_response):
... # environ["rouver.wildcard_path"] contains the remaining path
... return respond(start_response)
>>> router.add_routes([
... ("wild/*", "GET", get_wildcard),
... ])
Sub-routers:
>>> def get_sub(environ, start_response):
... return respond(start_response)
>>> sub_router = Router()
>>> sub_router.add_routes([
... ("sub", "GET", get_sub),
... ])
>>> router.add_sub_router("parent", sub_router)
Argument Handling
>>> from rouver.args import Multiplicity, parse_args
>>> from rouver.response import respond_with_json
>>> def get_count_with_args(request, path, start_response):
... args = parse_args(request.environ, [
... ("count", int, Multiplicity.REQUIRED),
... ])
... return respond_with_json({"count": args["count"]})
WSGI Testing
>>> from rouver.test import create_request, test_wsgi_app
>>> request = create_request("GET", "/my/path")
>>> response = test_wsgi_app(app, request)
>>> response.assert_status(HTTPStatus.OK)
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
rouver-2.4.2.tar.gz
(33.1 kB
view details)
Built Distribution
rouver-2.4.2-py3-none-any.whl
(39.5 kB
view details)
File details
Details for the file rouver-2.4.2.tar.gz
.
File metadata
- Download URL: rouver-2.4.2.tar.gz
- Upload date:
- Size: 33.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | acef78fb54157920176eb78aa1818639a455e973d5ecd1c5496c35691763d302 |
|
MD5 | 3686d6097d14315e728398921337ea37 |
|
BLAKE2b-256 | fc218d5168e0a4b708568d2947cd73b47fe6d4a2f4e794de58d45ed6a36722d1 |
File details
Details for the file rouver-2.4.2-py3-none-any.whl
.
File metadata
- Download URL: rouver-2.4.2-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.4.2 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1023cef187032dfd963d6ab3bb41c4867fcfec3e1149fa5b54baf588f6c176ca |
|
MD5 | 86a51b8e7bfa001fc7e3a9e25a26ae61 |
|
BLAKE2b-256 | e79f90f1a45c77f0773aacd094853149d7fa75bb627bb1ef5cd3545403552831 |