Skip to content

handlers.py

Provides base class for class-based handlers.

BaseHandler

Base class for class-based handlers.

Source code in jetweb/handlers.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class BaseHandler:
    """
    Base class for class-based handlers.
    """

    def dispatch(self, context: Context) -> Union[Response, object]:
        """
        Dispatch request to appropriate HTTP method handler.

        :param context: Context values for current request.
        :returns: Handler return value (Response or any object).
        :raises HTTPException(405): If method is not implemented.
        """
        handler = getattr(self, context["request"].method.lower(), None)
        if handler:
            return handler(**context.params_for(handler))
        raise HTTPException(status=405)

dispatch(context)

Dispatch request to appropriate HTTP method handler.

Parameters:

Name Type Description Default
context Context

Context values for current request.

required

Returns:

Type Description
Union[Response, object]

Handler return value (Response or any object).

Raises:

Type Description
HTTPException(405)

If method is not implemented.

Source code in jetweb/handlers.py
17
18
19
20
21
22
23
24
25
26
27
28
def dispatch(self, context: Context) -> Union[Response, object]:
    """
    Dispatch request to appropriate HTTP method handler.

    :param context: Context values for current request.
    :returns: Handler return value (Response or any object).
    :raises HTTPException(405): If method is not implemented.
    """
    handler = getattr(self, context["request"].method.lower(), None)
    if handler:
        return handler(**context.params_for(handler))
    raise HTTPException(status=405)