You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the above command, we are providing the path in the format of `python_module:FastStream`. Alternatively, you can also specify `asyncapi.json` or `asyncapi.yaml` to serve the AsyncAPI documentation.
24
+
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.
23
25
24
26
=== "JSON"
25
27
```shell
@@ -31,7 +33,7 @@ In the above command, we are providing the path in the format of `python_module:
After running the command, it should serve the AsyncAPI documentation on port **8000** and display the following logs in the terminal.
36
+
After running the command, the **AsyncAPI** documentation will be served on port **8000**, and the terminal should display the following logs.
35
37
36
38
```{.shell .no-copy}
37
39
INFO: Started server process [2364992]
@@ -52,6 +54,98 @@ And you should be able to see the following page in your browser:
52
54
!!! tip
53
55
The command also offers options to serve the documentation on a different host and port.
54
56
57
+
## Built-in ASGI for FastStream Applications
58
+
59
+
FastStream includes lightweight [**ASGI** support](../asgi.md){.internal-link} that you can use to serve both your application and the **AsyncAPI** documentation.
60
+
61
+
```python linenums="1"
62
+
from faststream import FastStream
63
+
from faststream.kafka import KafkaBroker
64
+
65
+
broker = KafkaBroker()
66
+
67
+
@broker.subscriber('topic')
68
+
asyncdefmy_handler(msg: str) -> None:
69
+
print(msg)
70
+
71
+
app = FastStream(broker).as_asgi(
72
+
asyncapi_path="/docs/asyncapi",
73
+
)
74
+
75
+
if__name__=="__main__":
76
+
import uvicorn
77
+
uvicorn.run(app, host="0.0.0.0", port=8000)
78
+
```
79
+
80
+
After running the script, the **AsyncAPI** docs will be available at: <http://localhost:8000/docs/asyncapi>
81
+
82
+
## Integration with Different HTTP Frameworks (**FastAPI** Example)
83
+
84
+
**FastStream** provides two robust approaches to combine your message broker documentation with any **ASGI** web frameworks.
85
+
You can choose the method that best fits with your application architecture.
86
+
87
+
=== "Option 1"
88
+
```python linenums="1" hl_lines="23-26"
89
+
from typing import AsyncIterator
90
+
from contextlib import asynccontextmanager
91
+
92
+
from fastapi import FastAPI, responses
93
+
from faststream import FastStream
94
+
from faststream.asyncapi import get_asyncapi_html, get_app_schema
0 commit comments