pip install routedsl
Compose everything in one place
from routedsl import *
routes = Routes() (
GET / 'users' / ('user_id', User, "User identifier")
| HEADERS | Headers
| RETURNS | JSON [ User ]
| HANDLER | get_user_info
| GUARDS | ( Headers.content_type | IS | 'application/json'
)
| DOCS | """Get a user profile in JSON format"""
)(
POST / 'users' / ('user_id', User)
| HEADERS | Headers
| PAYLOAD | JSON [ User ]
| RETURNS | OK [ JSON [ bool ] ]
| HANDLER | update_user_info
)
or define pieces separately, then assemble your routing map:
DefaultHeaders = HEADERS | Headers
DefaultHandler = HANDLER | default_handler
DefaultEndpoint = ( GET / DefaultHeaders
| DefaultHandler )
routes = Routes() | DefaultEndpoint
Use nesting under common prefix
routes = (routes / 'users' / ('user_id', User)) (
POST / 'edit'
| HEADERS | Headers
| RETURNS | JSON [ User ]
| HANDLER | update_user_info
)
Find out more from Official Documentation.