Route functions by a http path
Project description
http-router – A simple router for HTTP applications
Requirements
python >= 3.7
Installation
http-router should be installed using pip:
pip install http-router
Usage
from http_router import Router
router = Router(trim_last_slash=True)
# Plain path
@router.route('/simple')
def simple(request):
return 'simple'
# Multiple paths are supported
@router.route('/', '/home')
def index(request):
return 'index'
# Bind HTTP Methods
@router.route('/only-post', methods=['POST'])
def only_post(request):
return 'only-post'
# Regex Expressions are supported
@router.route('/regex(/opt)?')
def optional(request):
return 'opt'
# Dynamic routes are here
@router.route('/order/{id}')
def order1(request, id=None):
return 'order-%s' % id
# Dynamic routes with regexp
@router.route('/order/{id:\d+}')
def order2(request, id=None):
return 'order-%s' % id
print(router('/order/100'))
# <function order2>, {'id': '100'}
Bug tracker
If you have any suggestions, bug reports or annoyances please report them to the issue tracker at https://github.com/klen/http-router/issues
Contributing
Development of the project happens at: https://github.com/klen/http-router
License
Licensed under a MIT license.
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
Close
Hashes for http_router-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f473b60f40b5f4f337d55179c4a3a9ec7aca7dc5aee75554afcaba948e1daee |
|
MD5 | 4c6ad559b2093bce8c093c7e90da5179 |
|
BLAKE2b-256 | 683b0be3885dfd5c46bcda396a23e32abfdaea11631ea61db6136f601ac3ea49 |