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(request, path, start_response): ... return respond_with_html(start_response, "<div>Foo</div>") >>> def get_count(request, path, 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(request, path, 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), ... ])
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 Distribution
rouver-0.2.0.tar.gz
(13.3 kB
view details)
File details
Details for the file rouver-0.2.0.tar.gz
.
File metadata
- Download URL: rouver-0.2.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0e2aaeef895924b344bf9bd287ce415491177dbe70c3bd8894e2c46fe38bcbb |
|
MD5 | 997a231f43c8e8dac91832e1b69b695d |
|
BLAKE2b-256 | c20b6896494ca041b5607903877d88a6c527bbbe911e1a32af997864ddefa35e |