Skip to main content

uRouter

https://img.shields.io/travis/com/theruziev/urouter.svg?style=flat-square https://img.shields.io/codecov/c/github/theruziev/urouter.svg?style=flat-square

Installation

pip install urouter

Supported web frameworks

Quickstart

Define handler in router

from aiohttp import web
from urouter.exporters.aiohttp_exporter import AioHttpRouter
app = web.Application()

 async def handler(request):
    return web.Response(text="Hello World")

router = AioHttpRouter(app)

router.get("/home", handler)

# At this point aiohttp is ready to register all routes
router.export()

Define global middleware for all routes

from aiohttp import web
from urouter.exporters.aiohttp_exporter import AioHttpRouter
app = web.Application()

@web.middleware
async def info_middleware(request, handler):
    # some operation before handle request
    response = await handler(request)
    return response

 async def handler(request):
    return web.Response(text="Hello World")

router = (AioHttpRouter(app)
            .use(info_middleware))

# Register handler
router.get("/home", handler)

# At this point aiohttp is ready to register all routes
router.export()

Define inline middleware (run only for specific handler)

from aiohttp import web
from urouter.exporters.aiohttp_exporter import AioHttpRouter
app = web.Application()

@web.middleware
async def info_middleware(request, handler):
    # some operation before handle request
    response = await handler(request)
    return response

 async def handler(request):
    return web.Response(text="Hello World")

router = AioHttpRouter(app)

# Middleware registered only for `/home` route
router.include(info_middleware).get("/home", handler)

# At this point aiohttp is ready to register all routes
router.export()

Define subrouter

from aiohttp import web
from urouter.exporters.aiohttp_exporter import AioHttpRouter
app = web.Application()

@web.middleware
async def info_middleware(request, handler):
    # some operation before handle request
    response = await handler(request)
    return response

 async def handler(request):
    return web.Response(text="Hello World")

 async def sub_handler(request):
    return web.Response(text="Hello World")


router = AioHttpRouter(app)

router.include(info_middleware).get("/home", handler)

# Create new router
subrouter = router.make_router()
subrouter.get("/hello", sub_handler)

# All registered router become starts with prefix `/sub/`
# `/hello` becomes `/sub/hello`
router.mount("/sub", subrouter)

# At this point aiohttp is ready to register all routes
router.export()

Private/Public router

from aiohttp import web
from urouter.exporters.aiohttp_exporter import AioHttpRouter
app = web.Application()

async def auth_middleware(request, handler):

    return web.HTTPForbidden()

async def public(request):
    return web.Response(text="Hello World")

async def private(request):
    return web.Response(text="Private Zone")

router = AioHttpRouter(app)
private_route = router.make_router().use(auth_middleware)

# Adding public handler
router.get("/home", public)

# Adding public handler
private_route.get("/private", private)

# Mount private router to main router
router.mount("/", private_route)

# At this point aiohttp is ready to register all routes
router.export()

Metadata

Release files for urouter 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for urouter 0.1.2
File Size Uploaded Provenance Actions
urouter-0.1.2.tar.gz 4.2 kB Without provenance Details for urouter-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for urouter 0.1.2
File Interpreter ABI Platform Actions
urouter-0.1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details for urouter-0.1.2-py2.py3-none-any.whl

Total release size: 10.4 kB

Release files / urouter-0.1.2.tar.gz

Download URL urouter-0.1.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5cd9636ba444e996ab1749011ab1a0e65f3b607adeab39bc90af1fec0232dac7
BLAKE2b-256 checksum
How to use checksums
752c9157582c079dd950972bf47d033aa092f833e98c707ef21ea4d3e688a136
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

Release files / urouter-0.1.2-py2.py3-none-any.whl

Download URL urouter-0.1.2-py2.py3-none-any.whl
Size 6.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
b0e48b2dcafe4f3d92c368949a17be7ec56fa251c7f6f15f191346c241559eab
BLAKE2b-256 checksum
How to use checksums
8ef13fe0e3787b383cd1e8ee0403bfeea74808e0885d26c7494db0d508e1ab2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.3

Security for urouter 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page