Chat API Reference β€” REST vs WebSocket

This page explains exactly which protocol to use for each action in the chat feature. Flutter and React teams should read this before integrating.


THE SIMPLE RULE

REST (HTTP) = load data that already exists (history, settings, members)

WebSocket (WSS) = send and receive real-time events (new messages, typing, deletions)

You use both together. This is how every major chat app works (WhatsApp, Slack, Telegram).


HOW FLUTTER USES BOTH

1. User opens a chatroom
   β†’ REST GET /rooms/{id}/messages/   ← load last 50 messages
   β†’ WSS connect to ws://...room/{id}/ ← open real-time connection

2. User is chatting
   β†’ New message arrives β†’ WebSocket pushes it β†’ append to bottom (NO REST CALL)
   β†’ User scrolls up β†’ REST GET /messages/?page=2 β†’ load older messages
   β†’ User sends message β†’ WebSocket send {type: message.send, content: "..."}
   β†’ All other connected members receive it instantly via WebSocket

3. User closes the screen
   β†’ REST POST /rooms/{id}/read/ ← mark as read
   β†’ WebSocket disconnects automatically

WEBSOCKET CONNECTIONS

Community Chatroom

wss://api.fittrybe.com/ws/chat/room/{chatroom_id}/?token=JWT_ACCESS_TOKEN

Direct Messages

wss://api.fittrybe.com/ws/chat/dm/{other_user_id}/?token=JWT_ACCESS_TOKEN

How to get the token: Call POST /api/v1/auth/login/ β†’ copy data.access from the response.

Close codes: