A microframework
Project description
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"]})
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
rouver-0.8.3-py3-none-any.whl
(25.3 kB
view details)
File details
Details for the file rouver-0.8.3-py3-none-any.whl
.
File metadata
- Download URL: rouver-0.8.3-py3-none-any.whl
- Upload date:
- Size: 25.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b102b9424a78a98096b3a4c4d03d9b9eb91ac2acbda1043af1e7df9b92ca60 |
|
MD5 | eb901dce8dca7c5297fd4f728ae8a97f |
|
BLAKE2b-256 | f66241bb662c8fb56e0d32db6fe34c1992838ebcac72504dae70992dd0e61dbe |