Skip to main content

Router middleware for xweb.

Project description

xweb-router

Router middleware for xweb

Usage

from xweb import App

from xweb_router import Router

app = App()
router = Router()
nested = Router()

app.use(router)


@router.use('/')
async def middleware(ctx, fn):
    """Router Middleware"""
    print('middleware')
    await fn()


@router.post('/')
async def home(ctx):
    ctx.body = "Home"


@router.get('/{name}')
async def hello(ctx):
    """URL parameters"""
    ctx.body = f"Hello {ctx.params.name}"


router.use('/post')(nested)


@nested.get('/index')
async def index(ctx):
    ctx.body = "Nested Index"


if __name__ == '__main__':
    app.listen(8000)

Nested Router



          

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for xweb-router, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size xweb_router-0.1.1-py3-none-any.whl (2.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size xweb_router-0.1.1.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page