Browse Source

Merge 2fe7d300b7 into eb75fd078e

pull/15930/merge
Saurabh Vijay Salve 4 days ago
committed by GitHub
parent
commit
edad4b0911
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 17
      docs/en/docs/reference/sse.md
  2. 1
      docs/en/mkdocs.yml

17
docs/en/docs/reference/sse.md

@ -0,0 +1,17 @@
# Server-Sent Events - `EventSourceResponse` and `ServerSentEvent`
To stream Server-Sent Events (SSE), use `yield` in your *path operation function* and set `response_class=EventSourceResponse`.
If you need to set SSE fields like `event`, `id`, `retry`, or `comment`, you can `yield` `ServerSentEvent` objects instead of plain data.
Read more about it in the [FastAPI docs for Server-Sent Events (SSE)](https://fastapi.tiangolo.com/tutorial/server-sent-events/).
You can import them directly from `fastapi.sse`:
```python
from fastapi.sse import EventSourceResponse, ServerSentEvent
```
::: fastapi.sse.EventSourceResponse
::: fastapi.sse.ServerSentEvent

1
docs/en/mkdocs.yml

@ -213,6 +213,7 @@ nav:
- reference/httpconnection.md
- reference/response.md
- reference/responses.md
- reference/sse.md
- reference/middleware.md
- "":
- reference/openapi/index.md

Loading…
Cancel
Save