Skip to content

API ​

Base URL: same origin (this app uses relative /api and /ws). Errors: { "error": "message" }.

Auth (no token) ​

MethodPathBodyResponse
POST/api/auth/signupusername, email, password201 token + user
POST/api/auth/loginemail, password200 token + user

User: id, username, email, last_seen, created_at. Signup/Login need non-empty fields; username and email unique.

Protected (Bearer token) ​

Header: Authorization: Bearer <token>

MethodPathDescription
GET/api/users/search?q=Search users; exclude self
PUT/api/users/meBody { "username" }.
GET/api/users/keys?ids=<id>&ids=<id>Device keys for users
POST/api/conversationstype, title?, member_ids
GET/api/conversationsList conversations
GET/api/conversations/:idConversation + members
DELETE/api/conversations/:idAdmin only; full delete
GET/api/conversations/:id/membersParticipant list
POST/api/conversations/:id/membersBody { "member_ids" }.
DELETE/api/conversations/:id/members/:userIdAdmin only; remove member
POST/api/conversations/:id/readMark conversation read
GET/api/messages?conversation_id=...Paginated; next_page
GET/api/messages/unread?conversation_id=...Unread messages (paginated)
POST/api/e2ee/devicesRegister current device key
GET/api/e2ee/devicesList my devices
DELETE/api/e2ee/devices/:idRevoke my device
GET/api/users/me/e2ee/backupGet encrypted key backup
PUT/api/users/me/e2ee/backupUpsert encrypted key backup

POST conversations: GROUP requires title. Creator is ADMIN. DIRECT conversations are de-duplicated: if a DIRECT conversation already exists between the two users, the server returns it instead of creating a new one.

POST conversations and member changes require X-Device-Id header. The body must include e2ee_keys (wrapped conversation keys) for all participants/devices. GET messages supports page_size and page_state. Response is { "messages", "next_page" }; each message has sender_name.

GET /api/conversations?include_unread=1 adds unread_count (capped at 99) and unread_overflow to each conversation.

GET /api/messages/unread returns messages where created_at is newer than the caller's participants.last_read_at for that conversation.

POST /api/conversations/:id/read accepts optional body { "read_at_ms": <unix_ms> }.

WebSocket ​

URL: ws(s)://<host>/ws

Auth: the client must send {"type":"auth","content":"<jwt>"} as the first frame within 5 seconds of the upgrade. The server closes with code 4001 on missing/invalid/expired token. The token is intentionally not passed in the URL to keep it out of access logs and browser history.

Origins: the upgrade is gated by the backend's ALLOWED_ORIGINS env var (comma-separated list of allowed Origin headers). If unset, only same-origin requests with no Origin header are accepted.

Client → server (JSON):

  • auth: type, content=<jwt> (first frame only).
  • chat: type, conversation_id, content (non-empty, max 5000; must be member).
  • typing: type, conversation_id.

Server → client: type one of chat, typing, new_conversation, conversation_deleted, key_rotated, removed_from_conversation. For chat: sender_id, sender_name, content, timestamp set by server.