We're proud to announce the addition of SubRouters to Robyn. This feature allows developers to create subrouters, providing a convenient way to group routes together.
The functionality of SubRouters extends to both normal routes and web sockets, acting as a smaller-scale replica of the main router. SubRouters can be utilized in exactly the same way as the main router, with the minor prerequisite of adding the SubRouter to the main router.
We hope you enjoy the increased flexibility this feature brings to your routing capabilities in Robyn! As always, we look forward to your feedback.
What's Changed
- Update features.md - change query param syntax by @urjitbhatia in https://github.com/sansyrox/robyn/pull/520
- Comply with pyproject definition by @Kludex in https://github.com/sansyrox/robyn/pull/521
- [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/sansyrox/robyn/pull/523
- Routers by @Noborita9 and @sansyrox in https://github.com/sansyrox/robyn/pull/497
New Contributors
- @urjitbhatia made their first contribution in https://github.com/sansyrox/robyn/pull/520
Sample Usage
SubRouters
You can create subrouters in Robyn. This is useful when you want to group routes together.
Subrouters can be used for both normal routes and web sockets. They are basically a mini version of the main router and can be used in the same way.
The only caveat is that you need to add the subrouter to the main router.
from robyn import Robyn, SubRouter
app = Robyn(__file__)
sub_router = SubRouter("/sub_router")
@sub_router.get("/hello")
def hello():
return "Hello, world"
web_socket = SubRouter("/web_socket")
@web_socket.message()
async def hello():
return "Hello, world"
app.add_sub_router(sub_router)
Full Changelog: https://github.com/sansyrox/robyn/compare/v0.31.0...v0.32.0