Skip to content

avanov/routedsl

Repository files navigation

https://github.com/avanov/routedsl/workflows/GitHub%20CI/badge.svg?branch=develop https://travis-ci.org/avanov/routedsl.svg?branch=develop https://circleci.com/gh/avanov/routedsl/tree/develop.svg?style=svg https://coveralls.io/repos/github/avanov/routedsl/badge.svg?branch=develop Requirements Status Documentation Status Latest PyPI Release

Python eDSL for your Web Routes

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.

About

Python eDSL for your Web Routes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published