Home / Class/ APIWebSocketRoute Class — fastapi Architecture

APIWebSocketRoute Class — fastapi Architecture

Architecture documentation for the APIWebSocketRoute class in routing.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  400570c6_159a_07b5_2e94_ba32f34336f9["APIWebSocketRoute"]
  de395a51_26f8_3424_1af0_2f5bef39c893["routing.py"]
  400570c6_159a_07b5_2e94_ba32f34336f9 -->|defined in| de395a51_26f8_3424_1af0_2f5bef39c893
  0df3979a_d2ac_6dd9_1bb1_6629b89a941b["__init__()"]
  400570c6_159a_07b5_2e94_ba32f34336f9 -->|method| 0df3979a_d2ac_6dd9_1bb1_6629b89a941b
  a1db8f82_73d2_f689_481a_3dbbe1595935["matches()"]
  400570c6_159a_07b5_2e94_ba32f34336f9 -->|method| a1db8f82_73d2_f689_481a_3dbbe1595935

Relationship Graph

Source Code

fastapi/routing.py lines 514–553

class APIWebSocketRoute(routing.WebSocketRoute):
    def __init__(
        self,
        path: str,
        endpoint: Callable[..., Any],
        *,
        name: Optional[str] = None,
        dependencies: Optional[Sequence[params.Depends]] = None,
        dependency_overrides_provider: Optional[Any] = None,
    ) -> None:
        self.path = path
        self.endpoint = endpoint
        self.name = get_name(endpoint) if name is None else name
        self.dependencies = list(dependencies or [])
        self.path_regex, self.path_format, self.param_convertors = compile_path(path)
        self.dependant = get_dependant(
            path=self.path_format, call=self.endpoint, scope="function"
        )
        for depends in self.dependencies[::-1]:
            self.dependant.dependencies.insert(
                0,
                get_parameterless_sub_dependant(depends=depends, path=self.path_format),
            )
        self._flat_dependant = get_flat_dependant(self.dependant)
        self._embed_body_fields = _should_embed_body_fields(
            self._flat_dependant.body_params
        )
        self.app = websocket_session(
            get_websocket_app(
                dependant=self.dependant,
                dependency_overrides_provider=dependency_overrides_provider,
                embed_body_fields=self._embed_body_fields,
            )
        )

    def matches(self, scope: Scope) -> tuple[Match, Scope]:
        match, child_scope = super().matches(scope)
        if match != Match.NONE:
            child_scope["route"] = self
        return match, child_scope

Domain

Defined In

Frequently Asked Questions

What is the APIWebSocketRoute class?
APIWebSocketRoute is a class in the fastapi codebase, defined in fastapi/routing.py.
Where is APIWebSocketRoute defined?
APIWebSocketRoute is defined in fastapi/routing.py at line 514.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free