Перейти к содержанию

Handlers

Warning

The current page still doesn't have a translation for this language.

But you can help translating it: Contributing.

This is the reference for the Handlers that contains all the parameters, attributes and functions.

ravyn.get module-attribute

get = _create_handler_decorator('GET', HTTP_200_OK)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.post module-attribute

post = _create_handler_decorator('POST', HTTP_201_CREATED)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.put module-attribute

put = _create_handler_decorator('PUT', HTTP_200_OK)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.patch module-attribute

patch = _create_handler_decorator('PATCH', HTTP_200_OK)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.delete module-attribute

delete = _create_handler_decorator(
    "DELETE", HTTP_204_NO_CONTENT
)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.route module-attribute

route = _create_route_decorator(is_webhook=False)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.head module-attribute

head = _create_handler_decorator('HEAD', HTTP_200_OK)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.options module-attribute

options = _create_handler_decorator('OPTIONS', HTTP_200_OK)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.trace module-attribute

trace = _create_handler_decorator('TRACE', HTTP_200_OK)
        - path
        - summary
        - description
        - status_code
        - content_encoding
        - content_media_type
        - include_in_schema
        - background
        - dependencies
        - exception_handlers
        - permissions
        - middleware
        - media_type
        - response_class
        - response_cookies
        - response_headers
        - deprecated
        - security
        - operation_id
        - response_description
        - responses

ravyn.websocket

websocket(
    path=None,
    *,
    name=None,
    dependencies=None,
    exception_handlers=None,
    middleware=None,
    permissions=None,
    before_request=None,
    after_request=None,
)
PARAMETER DESCRIPTION
path

Relative path of the handler. The path can contain parameters in a dictionary like format and if the path is not provided, it will default to /.

Example

@websocket()

Example with parameters

@websocket(path="/{age: int}")

TYPE: Optional[str] DEFAULT: None

name

The name for the Gateway. The name can be reversed by url_path_for().

TYPE: Optional[str] DEFAULT: None

dependencies

A dictionary of string and Inject instances enable application level dependency injection.

TYPE: Optional[Dependencies] DEFAULT: None

exception_handlers

A dictionary of exception types (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of handler(request, exc) -> response and may be be either standard functions, or async functions.

TYPE: Optional[ExceptionHandlerMap] DEFAULT: None

middleware

A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or Lilya Middleware as they are both converted internally. Read more about Python Protocols.

TYPE: Optional[list[Middleware]] DEFAULT: None

permissions

A list of permissions to serve the application incoming requests (HTTP and Websockets).

TYPE: Optional[list[Permission]] DEFAULT: None

before_request

A list of events that are triggered before the application processes the request.

TYPE: Union[Sequence[Callable[..., Any]], None] DEFAULT: None

after_request

A list of events that are triggered after the application processes the request.

TYPE: Union[Sequence[Callable[..., Any]], None] DEFAULT: None

Source code in ravyn/routing/handlers.py
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def websocket(
    path: Annotated[
        Optional[str],
        Doc(
            """
            Relative path of the `handler`.
            The path can contain parameters in a dictionary like format
            and if the path is not provided, it will default to `/`.

            **Example**

            ```python
            @websocket()
            ```

            **Example with parameters**

            ```python
            @websocket(path="/{age: int}")
            ```
            """
        ),
    ] = None,
    *,
    name: Annotated[
        Optional[str],
        Doc(
            """
            The name for the Gateway. The name can be reversed by `url_path_for()`.
            """
        ),
    ] = None,
    dependencies: Annotated[
        Optional["Dependencies"],
        Doc(
            """
            A dictionary of string and [Inject](https://ravyn.dev/dependencies/) instances enable application level dependency injection.
            """
        ),
    ] = None,
    exception_handlers: Annotated[
        Optional["ExceptionHandlerMap"],
        Doc(
            """
            A dictionary of [exception types](https://ravyn.dev/exceptions/) (or custom exceptions) and the handler functions on an application top level. Exception handler callables should be of the form of `handler(request, exc) -> response` and may be be either standard functions, or async functions.
            """
        ),
    ] = None,
    middleware: Annotated[
        Optional[list["Middleware"]],
        Doc(
            """
            A list of middleware to run for every request. The middlewares of an Include will be checked from top-down or [Lilya Middleware](https://www.lilya.dev/middleware/) as they are both converted internally. Read more about [Python Protocols](https://peps.python.org/pep-0544/).
            """
        ),
    ] = None,
    permissions: Annotated[
        Optional[list["Permission"]],
        Doc(
            """
            A list of [permissions](https://ravyn.dev/permissions/) to serve the application incoming requests (HTTP and Websockets).
            """
        ),
    ] = None,
    before_request: Annotated[
        Union[Sequence[Callable[..., Any]], None],
        Doc(
            """
            A list of events that are triggered before the application processes the request.
            """
        ),
    ] = None,
    after_request: Annotated[
        Union[Sequence[Callable[..., Any]], None],
        Doc(
            """
            A list of events that are triggered after the application processes the request.
            """
        ),
    ] = None,
) -> Callable[[F], WebSocketHandler]:
    def wrapper(func: Any) -> WebSocketHandler:
        handler = WebSocketHandler(
            path=path,
            dependencies=dependencies,
            exception_handlers=exception_handlers,
            permissions=permissions,
            middleware=middleware,
            name=name,
            before_request=before_request,
            after_request=after_request,
        )
        handler.fn = func
        handler.handler = func
        handler.validate_websocket_handler_function()
        return handler

    return wrapper
        - path
        - dependencies
        - exception_handlers
        - permissions
        - middleware