Skip to content

Latest commit

 

History

History
92 lines (66 loc) · 5.04 KB

api.md

File metadata and controls

92 lines (66 loc) · 5.04 KB

HTTP and WebSocket API

Base URL in dev: http://localhost:3000. Cookie: jwt_token. CORS allows CLIENT_ORIGIN with credentials.

Unless noted, routes need a valid session.

Health

GET /health

200 { "status": "ok" }. No auth.

Auth

Method Path Auth Notes
POST /auth/signup no Rate limited: 10 / hour / IP
POST /auth/signin no Rate limited: 30 / 15 min / IP and 10 / 15 min / account
GET /auth/me yes { user: { id, username, email, avatarId, isGuest } }. A guest's username is their display name and email is null
POST /auth/logout cookie optional Revokes if present, always clears cookie
GET /auth/github no 503 if OAuth env is missing
GET /auth/github/callback no Redirects to the web app
GET /auth/sessions yes Active sessions, current: true on the caller
DELETE /auth/sessions/:id yes Own sessions only
POST /auth/sessions/revoke-all yes Body { keepCurrent?: boolean }

Signup body: { username, email, password }. Sign-in body: { email, password }.

Workspaces

Method Path Notes
GET /workspaces Workspaces the caller belongs to, with expiresAt
POST /workspaces { name, expiresIn? }, expiresIn one of 1h, 24h, 7d, never (default). Caller becomes owner, #general is created. Returns { workspaceId, expiresAt }. Guests get 403
GET /workspaces/:id Name, expiresAt, channels, members
DELETE /workspaces/:id Owner. Ends the workspace: deletes it and everything in it for good, then sends workspace_ended. 204, or 404 gone if it already ended. 20 / hour / user
POST /workspaces/:id/invite Owner. Returns { token, expiresAt }. Lasts 7 days or until the workspace expires. 20 / hour / user
GET /workspaces/:id/invites Owner. No tokens in the list
DELETE /workspaces/:id/invites/:inviteId Owner
POST /workspaces/join/:token Join with your account. 20 / hour / user, 60 / hour / IP. Guests get 403

Invite links

Method Path Auth Notes
GET /invites/:token no { workspaceId, workspaceName, expiresAt }. 60 / min / IP
POST /invites/:token/guest no { displayName }. Creates a guest and sets the session cookie. 201 { workspaceId, recoveryCode }, 400 invalid_name, 409 name_taken, 409 signed_in. 10 / hour / IP
POST /guest/recover no { code }. Opens a session for the same guest. Returns { workspaceId }. 30 / hour / IP
POST /guest/recovery-code guest Returns { recoveryCode } and invalidates the previous code

Every invite that no longer works (unknown, revoked, expired, or its workspace ended or expired) gets the same answer from all three join routes: 404 { "status": "gone", "message": "This huddle has ended or never existed." }. See temporary workspaces.

Channels and messages

Method Path Notes
POST /workspaces/:id/channels Owner or admin. { name }. All current members are added
GET /workspaces/:id/channels
GET /channels/:id Name, createdAt, members with their workspace role
DELETE /channels/:id Owner or admin. Ends the channel: deletes it with its messages and memberships for good, then sends channel_deleted to every member
GET /channels/:id/messages Pages of 50, ordered by (createdAt, id). No cursor: newest first. ?before=<messageId>: the page older than it, newest first (?cursor= is the old name). ?after=<messageId>: the page newer than it, oldest first. Returns { batchMessage, nextCursor, hasMore }. Keep passing nextCursor the same way while hasMore
POST /channels/:id/messages { content, clientMessageId? }. Fans out over the socket. Repeating a clientMessageId returns the saved message, no second copy. Shares the send limit with the socket
PUT /channels/:id/read { messageId }. Moves the caller's read marker forward, never back. 120 / min / user

GET /workspaces/:id also returns unreadChannelIds: channels where someone else posted after the caller's read marker.

The web UI uses the socket for send and REST for history.

Direct messages

Method Path Notes
GET /dm/:userId Query workspaceId required, optional cursor. Newest 50
POST /dm/:userId { content, workspaceId }

Both people must be in that workspace. Not used by the SPA. Does not fan out on the socket.

WebSocket

URL: same host as HTTP, ws: / wss: matching the page. Cookie on upgrade.

Client frames and server frames are listed in realtime. Maximum frame 16 KB. Message content max 4000 characters.

Error frames look like:

{ "type": "error", "code": "channel_not_found", "message": "Channel not found", "clientMessageId": "…" }

code values you will actually see: Zod failures, channel_not_found, forbidden, not_supported, plus join/send membership failures from channel-access.ts.