Skip to main content

Route functions by a http path

Project description

http-router – A simple router for HTTP applications

Tests Status PYPI Version

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


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

http_router-0.1.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file http_router-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: http_router-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for http_router-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bc5909dce89db80f3cdef06bb4554b3220a3388826d5eb5908d68aeff5d5a62
MD5 3a3484d5356c6eec79ce6111bf36a518
BLAKE2b-256 56363753cb8cf6a0e646863faa28199145955c59693802ffa1c12b1cd097ba43

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page