Serving the AsyncAPI Documentation#
Using CLI and http.server#
FastStream provides a command to serve the AsyncAPI documentation.
Note
This feature requires an Internet connection to obtain the AsyncAPI HTML via CDN.
In the above command, the path is specified in the format of python_module:FastStream. Alternatively, you can also specify asyncapi.json or asyncapi.yaml to serve the AsyncAPI documentation.
After running the command, the AsyncAPI documentation will be served on port 8000, and the terminal should display the following logs.
INFO: Started server process [2364992]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
And you should be able to see the following page in your browser:
Tip
The command also offers options to serve the documentation on a different host and port.
Built-in ASGI for FastStream Applications#
FastStream includes lightweight ASGI support that you can use to serve both your application and the AsyncAPI documentation.
Also, you can configure AsyncAPI route behavior using a special class:
After running the script, the AsyncAPI docs will be available at: http://localhost:8000/docs/asyncapi
Try It Out#
The AsyncAPI documentation page includes a built-in Try It Out feature that lets you publish test messages directly from the browser UI, without leaving the docs page.
Note
The Try It Out UI is powered by the asyncapi-try-it-plugin — a plugin for AsyncAPI that adds a Swagger-like interface to send test messages to message brokers. Thanks to the maintainers for this functionality.
By default, when you set asyncapi_path, a companion POST endpoint is automatically registered at {asyncapi_path}/try. The UI sends the message payload to this endpoint, which publishes it to your broker in test mode (without requiring a real broker connection).
To disable the feature, use AsyncAPIRoute with try_it_out=False:
If you want to point the Try It Out UI to an external backend (e.g. a separate service or a production broker URL), pass a custom try_it_out_url via AsyncAPIRoute:
Note
When try_it_out_url is set on AsyncAPIRoute, it overrides the URL the browser sends requests to. The local POST {asyncapi_path}/try endpoint is still registered and reachable regardless of try_it_out_url, unless you also pass try_it_out=False.
Integration with Different HTTP Frameworks (FastAPI Example)#
FastStream provides two robust approaches to combine your message broker documentation with any ASGI web frameworks. You can choose the method that best fits with your application architecture.
After running the app, the documentation will be available at:
- OpenAPI Docs: http://localhost:8000/docs
- AsyncAPI Docs: http://localhost:8000/docs/asyncapi
Customizing AsyncAPI Documentation#
FastStream also provides query parameters to show and hide specific sections of AsyncAPI documentation.
You can use the following parameters control the visibility of relevant sections:
sidebar: Whether to include the sidebar. Default is true.info: Whether to include the info section. Default is true.servers: Whether to include the servers section. Default is true.operations: Whether to include the operations section. Default is true.messages: Whether to include the messages section. Default is true.schemas: Whether to include the schemas section. Default is true.errors: Whether to include the errors section. Default is true.expandMessageExamples: Whether to expand message examples. Default is true.
For example, to hide the entire Servers section of the documentation, simply add servers=false as a query parameter, i.e., http://localhost:8000?servers=false. The resulting page would look like the image below:
Please use the above-listed query parameters to show and hide sections of the AsyncAPI documentation.


