• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    Python
  • Created almost 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Websocket 'broadcast' demo using FastAPI/Starlette

fastapi-websocket-broadcast

An example of the familiar 'chat' websocket demo app, implemented in FastAPI / Starlette.

Run with

uvicorn app:app

And then point your browser to http://localhost:8000. REST API documentation is available under the /docs endpoint.

Websocket interface

Data from the server is JSON in the form

{
    "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