Skip to content

get

faststream.asgi.handlers.get #

get(func)
Source code in faststream/asgi/handlers.py
def get(func: "UserApp") -> "ASGIApp":
    methods = ("GET", "HEAD")

    method_now_allowed_response = _get_method_not_allowed_response(methods)
    error_response = AsgiResponse(body=b"Internal Server Error", status_code=500)

    @wraps(func)
    async def asgi_wrapper(
        scope: "Scope",
        receive: "Receive",
        send: "Send",
    ) -> None:
        if scope["method"] not in methods:
            response: ASGIApp = method_now_allowed_response

        else:
            try:
                response = await func(scope)
            except Exception:
                response = error_response

        await response(scope, receive, send)
        return

    return asgi_wrapper