Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kthwaite/fastapi-websocket-broadcast
Websocket 'broadcast' demo using FastAPI/Starlette
https://github.com/kthwaite/fastapi-websocket-broadcast
async fastapi python3 starlette websocket
Last synced: 13 days ago
JSON representation
Websocket 'broadcast' demo using FastAPI/Starlette
- Host: GitHub
- URL: https://github.com/kthwaite/fastapi-websocket-broadcast
- Owner: kthwaite
- Created: 2019-02-15T18:08:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-19T13:00:37.000Z (3 months ago)
- Last Synced: 2024-09-03T07:01:59.358Z (2 months ago)
- Topics: async, fastapi, python3, starlette, websocket
- Language: Python
- Size: 69.3 KB
- Stars: 132
- Watchers: 4
- Forks: 23
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-fastapi - FastAPI Websocket Broadcast - Websocket 'broadcast' demo. (Projects / Open Source Projects)
- awesome-fastapi - FastAPI Websocket Broadcast - Websocket 'broadcast' demo. (Projects / Open Source Projects)
README
# fastapi-websocket-broadcast
An example of the familiar 'chat' websocket demo app, implemented in [FastAPI](https://github.com/tiangolo/fastapi) / [Starlette](https://github.com/encode/starlette).
Run with
```
uvicorn app:app
```And then point your browser to [http://localhost:8000](http://localhost:8000). REST API documentation is available under the `/docs` endpoint.
## Websocket interface
Data from the server is JSON in the form
```json
{
"type": ...,
"data": {
...
}
}
```Where `type` is one of:
- **ROOM_JOIN** - sent to a user on successfully joining the chatroom
- **USER_JOIN** - sent to all chatroom users when a new user joins the chatroom
- **USER_LEAVE** - sent to all chatroom users when a user leaves the chatroom
- **ERROR** - sent to one or more users in the event of a server error
- **MESSAGE** - chat message from one user, broadcast to all chatroom users
- **WHISPER** - private message from one user to another