# Rouver
A microframework for Python 3, based on werkzeug.
[![MIT License](https://img.shields.io/pypi/l/rouver.svg)](https://pypi.python.org/pypi/rouver/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/rouver)](https://pypi.python.org/pypi/rouver/)
[![GitHub](https://img.shields.io/github/release/srittau/rouver/all.svg)](https://github.com/srittau/rouver/releases/)
[![pypi](https://img.shields.io/pypi/v/rouver.svg)](https://pypi.python.org/pypi/rouver/)
[![Travis CI](https://travis-ci.org/srittau/rouver.svg?branch=master)](https://travis-ci.org/srittau/rouver)
## Routing
```python
>>> 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:
```python
>>> 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:
```python
>>> 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:
```python
>>> 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
```python
>>> 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
```python
>>> 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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/srittau/rouver",
"name": "rouver",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Sebastian Rittau",
"author_email": "srittau@rittau.biz",
"download_url": "https://files.pythonhosted.org/packages/a4/f5/0c6276b5deda473420ecc4563c38d25be3486032eda6051a02f69b85f5a7/rouver-2.6.3.tar.gz",
"platform": null,
"description": "# Rouver\n\nA microframework for Python 3, based on werkzeug.\n\n[![MIT License](https://img.shields.io/pypi/l/rouver.svg)](https://pypi.python.org/pypi/rouver/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/rouver)](https://pypi.python.org/pypi/rouver/)\n[![GitHub](https://img.shields.io/github/release/srittau/rouver/all.svg)](https://github.com/srittau/rouver/releases/)\n[![pypi](https://img.shields.io/pypi/v/rouver.svg)](https://pypi.python.org/pypi/rouver/)\n[![Travis CI](https://travis-ci.org/srittau/rouver.svg?branch=master)](https://travis-ci.org/srittau/rouver)\n\n## Routing\n\n```python\n>>> from rouver.router import Router\n>>> from rouver.response import respond_with_html, respond_with_json\n>>> def get_index(environ, start_response):\n... return respond_with_html(start_response, \"<div>Foo</div>\")\n>>> def get_count(environ, start_response):\n... return respond_with_json(start_response, {\"count\": 42})\n>>> router = Router()\n>>> router.add_routes([\n... (\"\", \"GET\", get_index),\n... (\"count\", \"GET\", get_count),\n... ])\n\n```\n\nRoutes with placeholders:\n\n```python\n>>> def get_addition(environ, start_response):\n... num1, num2 = path\n... return response_with_json(start_response, {\"result\": num1 + num2})\n>>> def numeric_arg(request, path, value):\n... return int(value)\n>>> router.add_template_handler(\"numeric\", numeric_arg)\n>>> router.add_routes([\n... (\"add/{numeric}/{numeric}\", \"GET\", get_addition),\n... ])\n```\n\nRoutes with wildcards:\n\n```python\n>>> def get_wildcard(environ, start_response):\n... # environ[\"rouver.wildcard_path\"] contains the remaining path\n... return respond(start_response)\n>>> router.add_routes([\n... (\"wild/*\", \"GET\", get_wildcard),\n... ])\n```\n\nSub-routers:\n\n```python\n>>> def get_sub(environ, start_response):\n... return respond(start_response)\n>>> sub_router = Router()\n>>> sub_router.add_routes([\n... (\"sub\", \"GET\", get_sub),\n... ])\n>>> router.add_sub_router(\"parent\", sub_router)\n```\n\n## Argument Handling\n\n```python\n>>> from rouver.args import Multiplicity, parse_args\n>>> from rouver.response import respond_with_json\n>>> def get_count_with_args(request, path, start_response):\n... args = parse_args(request.environ, [\n... (\"count\", int, Multiplicity.REQUIRED),\n... ])\n... return respond_with_json({\"count\": args[\"count\"]})\n```\n\n## WSGI Testing\n\n```python\n>>> from rouver.test import create_request, test_wsgi_app\n>>> request = create_request(\"GET\", \"/my/path\")\n>>> response = test_wsgi_app(app, request)\n>>> response.assert_status(HTTPStatus.OK)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A microframework",
"version": "2.6.3",
"project_urls": {
"Bug Tracker": "https://github.com/srittau/rouver/issues",
"Changes": "https://github.com/srittau/rouver/blob/main/CHANGELOG.md",
"GitHub": "https://github.com/srittau/rouver",
"Homepage": "https://github.com/srittau/rouver",
"Repository": "https://github.com/srittau/rouver"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5293043603378952b677fca0baf1c83256439b833f7817de4a5c6e3f53642a0c",
"md5": "3387c1869124ee4e4a7cffc470157535",
"sha256": "f5db1dcb4f0344a2c41484c7cd8363065e19f6792277d37aa2e14919d077333a"
},
"downloads": -1,
"filename": "rouver-2.6.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3387c1869124ee4e4a7cffc470157535",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 40116,
"upload_time": "2023-10-09T09:41:03",
"upload_time_iso_8601": "2023-10-09T09:41:03.724609Z",
"url": "https://files.pythonhosted.org/packages/52/93/043603378952b677fca0baf1c83256439b833f7817de4a5c6e3f53642a0c/rouver-2.6.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a4f50c6276b5deda473420ecc4563c38d25be3486032eda6051a02f69b85f5a7",
"md5": "a4465bbc46fb344c41e2219e0eb4e8b8",
"sha256": "b5c59f8fb096d0d51c094063c9ee88f70fe5f8c135f93a25a24f64242a0b602f"
},
"downloads": -1,
"filename": "rouver-2.6.3.tar.gz",
"has_sig": false,
"md5_digest": "a4465bbc46fb344c41e2219e0eb4e8b8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 33163,
"upload_time": "2023-10-09T09:41:05",
"upload_time_iso_8601": "2023-10-09T09:41:05.375983Z",
"url": "https://files.pythonhosted.org/packages/a4/f5/0c6276b5deda473420ecc4563c38d25be3486032eda6051a02f69b85f5a7/rouver-2.6.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-09 09:41:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "srittau",
"github_project": "rouver",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rouver"
}