Skip to content

elliotgao2/xweb-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xweb-router

Router middleware for xweb

Usage

from xweb import App

from xweb_router import Router

app = App()
router = Router()
app.use(router)

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

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

MiddleWare

from xweb import App

from xweb_router import Router

app = App()
router = Router()
app.use(router)


@router.use('/')
async def middleware(ctx, fn):
    """Router Middleware"""
    print('middleware')
    await fn()
    
@router.get('/')
async def home(ctx):
    ctx.body = "Home"
    
if __name__ == '__main__':
    app.listen(8000)

Router Parameters

from xweb import App

from xweb_router import Router

app = App()
router = Router()

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

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

Nested Router

from xweb import App

from xweb_router import Router

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

app.use(router)

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


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


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

About

Router middleware for xweb.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages