willpyre.router

class willpyre.router.OpenAPIRouter(config: None | Dict[str, Any] = None, description: str = '', schemes: List[str] = ['http', 'https'], version: str = '0.0.1', endpoint_prefix: str = '', openapi_url: str = '/openapi.json', oauth_redirect_url: str = '/openapi-rediect', tos_url: str = '/terms-of-service', openapi_version: str = '3.0.0', title: str = '', docs_url='/docs', tags: List[str] = [], dependencies=None, swagger_params=None, swagger_favicon: str = '/favicon.ico', definitions: List[Any] = [], license=None, contact=None, host=None)[source]

Bases: Router

OpenAPIRouter class has the HTTP methods, paths, and handlers and other info required for OpenAPI based docs.

Parameters:
  • self – The class willpyre.structure.Request

  • description (str) – Description of the API

  • schemes (List[str]) – Default = [‘http’,’https’]

  • version (str) – Default = “0.0.1”. Version of your API.

  • endpoint_prefix (str) – prefix of paths for internal info.

  • body (str) – The HTTP request body.

  • oauth_redirect_url (str) – Default = “/openapi-rediect”.

  • tos_url (str) – Default=”/terms-of-service”.

  • docs_url (str) – Default=”/docs”.

  • tags (List[str]) – Default=[].

  • dependencies – Default=None.

  • swagger_params – Default=None.

  • swagger_favicon (str) – Default = “/favicon.ico”.

  • definitions (List[Any]) – Default = []

  • license – Default=None

  • contact – Default=None

  • host – Default=None

add_api_route(path: str, handler: Callable, methods: list = ['GET', 'POST'], middlewares: list = [], pass_through: list = [], endpoint_name: str = '', response_model=None, status: int = 200, deprecated: bool = False, operation_id=None, summary: str = '', openapi_extra=None, tags=[], consumes=['application/json'], produces=['application/json'], parameters=['parameters'], responses={'200': {'description': ''}}, security=[])[source]
add_route(path: str, method: str, handler: Callable, middlewares: list = [], pass_through: list = [], endpoint_name: str = '', response_model=None, status: int = 200, deprecated: bool = False, operation_id=None, summary: str = '', openapi_extra=None, tags=[], consumes=['application/json'], produces=['application/json'], parameters=['parameters'], responses={'200': {'description': ''}}, security=[], path_parameters=None, auto_path_parameters=True, no_docs: bool = False, body_model=None, body_parameters=None, **kwargs)[source]

This should be used to add a route with respect to an HTTP method to the router.

Parameters:
  • self – The Router

  • path (str) – The path to add

  • method (str) – The method to add for the router to handle.

  • handler – The function that will be called in response to this route for the given method.

  • endpoint_name – The name of the endpoint for this path.

  • middlewares – The list of middleware functions to call before calling the handler. Default: []

  • pass_through – The functions to pass the request and response through after the handler has returned a value.

connect(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a connect request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

fetch(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a fetch request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

get(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a get query to the path.

Usage:

@router.get('/'):
def landing(request,response):
  #Some application logic
  return response
Parameters:
  • selfRouter

  • path (str) – The Request path

  • name (str) – Endpoint name, default is none.

async handle(request: Request) Response[source]

The handle function wil handle the requests and send appropriate responses, based on the functions defined.

Parameters:
Returns:

willpyre.structure.Response

openapi()[source]
options(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on an options request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

patch(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a PATCH request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

post(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a post request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

put(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a put request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

trace(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a trace request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

willpyre.router.RouteData

alias of RouterData

class willpyre.router.Router(endpoint_prefix: str = '', config: None | Dict[str, Any] = None)[source]

Bases: StaticRouter

The Router class handles routing of URLs. You need to give an endpoint prefix if you are embedding it.

add_route(path: str, method: str, handler: Callable, endpoint_name: str = '', middlewares: list = [], pass_through: list = []) None[source]

This should be used to add a route with respect to an HTTP method to the router.

Parameters:
  • self – The Router

  • path (str) – The path to add

  • method (str) – The method to add for the router to handle.

  • handler – The function that will be called in response to this route for the given method.

  • endpoint_name – The name of the endpoint for this path.

  • middlewares – The list of middleware functions to call before calling the handler. Default: []

  • pass_through – The functions to pass the request and response through after the handler has returned a value.

add_ws_route(path: str, method: str, handler: Callable) None[source]
embed_router(mount_at: str, router) None[source]
async handle(request: Request) Response[source]

The handle function wil handle the requests and send appropriate responses, based on the functions defined.

Parameters:
Returns:

willpyre.structure.Response

async handleWS(scope: dict, send, recieve) None[source]
class willpyre.router.StaticRouter(endpoint_prefix='', config: None | Dict[str, Any] = None)[source]

Bases: object

StaticRouter class has the HTTP methods, paths, and handlers. Not meant for usage. Acts as a base class.

add_endpoint(route: str, name: str = '')[source]
add_method(method: str)[source]

This should be used to adding custom HTTP methods to the routing dictionary

Parameters:
  • self – The Router

  • method (str) – The method to add for the router to handle.

Raises:

NotImplementedError

add_route(path: str, method: str, handler: Callable, endpoint_name: str = '', middlewares: list = [], pass_through: list = []) None[source]

This should be used to add a route with respect to an HTTP method to the router.

Parameters:
  • self – The Router

  • path (str) – The path to add

  • method (str) – The method to add for the router to handle.

  • handler – The function that will be called in response to this route for the given method.

  • endpoint_name – The name of the endpoint for this path.

  • middlewares – The list of middleware functions to call before calling the handler. Default: []

  • pass_through – The functions to pass the request and response through after the handler has returned a value.

connect(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a connect request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

endpoint_for(name: str) str[source]
fetch(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a fetch request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

get(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a get query to the path.

Usage:

@router.get('/'):
def landing(request,response):
  #Some application logic
  return response
Parameters:
  • selfRouter

  • path (str) – The Request path

  • name (str) – Endpoint name, default is none.

async handle(request) Response[source]

The handle function wil handle the requests and send appropriate responses, based on the functions defined.

Parameters:
Returns:

willpyre.structure.Response

options(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on an options request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

patch(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a PATCH request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

post(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a post request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

put(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a put request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path

trace(path: str, name: str = '', **opts) Callable[source]

This is meant to be used as a decorator on a function, that will be executed on a trace request to the path.

Parameters:
  • selfRouter

  • path (str) – The Request path