Skip to content

serve_app

faststream.asyncapi.site.serve_app #

serve_app(schema: Schema, host: str, port: int) -> None

Serve the FastAPI application.

PARAMETER DESCRIPTION
schema

The schema object representing the API specification.

TYPE: Schema

host

The host address to run the application on.

TYPE: str

port

The port number to run the application on.

TYPE: int

RETURNS DESCRIPTION
None

None

Note

The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)

Source code in faststream/asyncapi/site.py
def serve_app(
    schema: "Schema",
    host: str,
    port: int,
) -> None:
    """Serve the FastAPI application.

    Args:
        schema: The schema object representing the API specification.
        host: The host address to run the application on.
        port: The port number to run the application on.

    Returns:
        None
    !!! note

        The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
    """
    import uvicorn
    from fastapi import FastAPI
    from fastapi.responses import HTMLResponse

    app = FastAPI()

    @app.get("/")
    def asyncapi(
        sidebar: bool = True,
        info: bool = True,
        servers: bool = True,
        operations: bool = True,
        messages: bool = True,
        schemas: bool = True,
        errors: bool = True,
        expandMessageExamples: bool = True,
    ) -> HTMLResponse:  # pragma: no cover
        """Generate an AsyncAPI HTML response.

        Args:
            sidebar (bool): Whether to include the sidebar. Default is True.
            info (bool): Whether to include the info section. Default is True.
            servers (bool): Whether to include the servers section. Default is True.
            operations (bool): Whether to include the operations section. Default is True.
            messages (bool): Whether to include the messages section. Default is True.
            schemas (bool): Whether to include the schemas section. Default is True.
            errors (bool): Whether to include the errors section. Default is True.
            expandMessageExamples (bool): Whether to expand message examples. Default is True.

        Returns:
            HTMLResponse: The generated HTML response.
        !!! note

            The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
        """
        return HTMLResponse(
            content=get_asyncapi_html(
                schema,
                sidebar=sidebar,
                info=info,
                servers=servers,
                operations=operations,
                messages=messages,
                schemas=schemas,
                errors=errors,
                expand_message_examples=expandMessageExamples,
                title=schema.info.title,
            )
        )

    uvicorn.run(app, host=host, port=port)

Last update: 2023-11-24