Skip to content

WebhookGateway class

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

How to import

from esmerald import WebhookGateway

esmerald.WebhookGateway

WebhookGateway(*, handler, name=None, include_in_schema=True, parent=None, deprecated=None, security=None, before_request=None, after_request=None, tags=None)

Bases: Path, Dispatcher, GatewayUtil

WebhookGateway object class used by Esmerald routes.

The WebhookGateway act as a brigde between the webhook handlers and the main Esmerald routing system.

Read more about WebhookGateway and how to use it.

Note

This is used for OpenAPI documentation purposes only.

PARAMETER DESCRIPTION
handler

An instance of handler.

TYPE: Union[WebhookHandler, View]

name

The name for the WebhookGateway.

TYPE: Optional[str] DEFAULT: None

include_in_schema

Boolean flag indicating if it should be added to the OpenAPI docs.

TYPE: bool DEFAULT: True

parent

Who owns the Gateway. If not specified, the application automatically it assign it.

This is directly related with the application levels.

TYPE: Optional[ParentType] DEFAULT: None

deprecated

Boolean flag for indicating the deprecation of the Gateway and to display it in the OpenAPI documentation..

TYPE: Optional[bool] DEFAULT: None

security

Used by OpenAPI definition, the security must be compliant with the norms. Esmerald offers some out of the box solutions where this is implemented.

The Esmerald security is available to automatically used.

The security can be applied also on a level basis.

For custom security objects, you must subclass esmerald.openapi.security.base.HTTPBase object.

TYPE: Optional[Sequence[SecurityScheme]] DEFAULT: None

before_request

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

Read more about the events.

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

after_request

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

Read more about the events.

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

tags

A list of strings tags to be applied to the path operation.

It will be added to the generated OpenAPI documentation.

Note almost everything in Esmerald can be done in levels, which means these tags on a Esmerald instance, means it will be added to every route even if those routes also contain tags.

TYPE: Optional[Sequence[str]] DEFAULT: None

Source code in esmerald/routing/gateways.py
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
def __init__(
    self,
    *,
    handler: Annotated[
        Union["WebhookHandler", View],
        Doc(
            """
            An instance of [handler](https://esmerald.dev/routing/webhooks/#handlers).
            """
        ),
    ],
    name: Annotated[
        Optional[str],
        Doc(
            """
            The name for the WebhookGateway.
            """
        ),
    ] = None,
    include_in_schema: Annotated[
        bool,
        Doc(
            """
            Boolean flag indicating if it should be added to the OpenAPI docs.
            """
        ),
    ] = True,
    parent: Annotated[
        Optional["ParentType"],
        Doc(
            """
            Who owns the Gateway. If not specified, the application automatically it assign it.

            This is directly related with the [application levels](https://esmerald.dev/application/levels/).
            """
        ),
    ] = None,
    deprecated: Annotated[
        Optional[bool],
        Doc(
            """
            Boolean flag for indicating the deprecation of the Gateway and to display it
            in the OpenAPI documentation..
            """
        ),
    ] = None,
    security: Annotated[
        Optional[Sequence["SecurityScheme"]],
        Doc(
            """
            Used by OpenAPI definition, the security must be compliant with the norms.
            Esmerald offers some out of the box solutions where this is implemented.

            The [Esmerald security](https://esmerald.dev/openapi/) is available to automatically used.

            The security can be applied also on a [level basis](https://esmerald.dev/application/levels/).

            For custom security objects, you **must** subclass
            `esmerald.openapi.security.base.HTTPBase` object.
            """
        ),
    ] = None,
    before_request: Annotated[
        Union[Sequence[Callable[[], Any]], None],
        Doc(
            """
            A `list` of events that are trigger after the application
            processes the request.

            Read more about the [events](https://lilya.dev/lifespan/).
            """
        ),
    ] = None,
    after_request: Annotated[
        Union[Sequence[Callable[[], Any]], None],
        Doc(
            """
            A `list` of events that are trigger after the application
            processes the request.

            Read more about the [events](https://lilya.dev/lifespan/).
            """
        ),
    ] = None,
    tags: Annotated[
        Optional[Sequence[str]],
        Doc(
            """
            A list of strings tags to be applied to the *path operation*.

            It will be added to the generated OpenAPI documentation.

            **Note** almost everything in Esmerald can be done in [levels](https://esmerald.dev/application/levels/), which means
            these tags on a Esmerald instance, means it will be added to every route even
            if those routes also contain tags.
            """
        ),
    ] = None,
) -> None:
    if is_class_and_subclass(handler, View):
        handler = handler(parent=self)  # type: ignore

    self.path = handler.path
    self.methods = getattr(handler, "http_methods", None)

    if not name:
        if not isinstance(handler, View):
            name = clean_string(handler.fn.__name__)
        else:
            name = clean_string(handler.__class__.__name__)

    self.handler = cast("Callable", handler)
    self.include_in_schema = include_in_schema

    self._interceptors: Union[List["Interceptor"], "VoidType"] = Void
    self.name = name
    self.dependencies: Any = {}
    self.interceptors: Sequence["Interceptor"] = []
    self.permissions: Sequence["Permission"] = []  # type: ignore
    self.middleware: Any = []
    self.exception_handlers: Any = {}
    self.response_class = None
    self.response_cookies = None
    self.response_headers = None
    self.deprecated = deprecated
    self.parent = parent
    self.security = security
    self.before_request = before_request
    self.after_request = after_request
    self.tags = tags or []
    (handler.path_regex, handler.path_format, handler.param_convertors, _) = compile_path(
        self.path
    )

    if self.is_handler(self.handler):  # type: ignore
        self.handler.name = self.name

        if not handler.operation_id:
            handler.operation_id = self.generate_operation_id(
                name=self.name,
                handler=self.handler,  # type: ignore
            )

handler instance-attribute

handler = cast('Callable', handler)

name instance-attribute

name = name

include_in_schema instance-attribute

include_in_schema = include_in_schema

parent instance-attribute

parent = parent

deprecated instance-attribute

deprecated = deprecated

security instance-attribute

security = security

tags instance-attribute

tags = tags or []