Rooms API
Endpoints for creating, listing, and managing chat rooms.
Overview
Chat rooms are either public (visible to all users) or private (visible only to members). Users can create, join, leave, and delete rooms.
Endpoint Summary
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /api/rooms | List rooms (public + private membership) | No |
| POST | /api/rooms | Create room | Yes |
| GET | /api/rooms/{id} | Get room by ID | No |
| DELETE | /api/rooms/{id} | Delete room | Yes |
| POST | /api/rooms/{id}/join | Join room | Yes |
| POST | /api/rooms/{id}/leave | Leave room | Yes |
| GET | /api/rooms/{id}/users | List active users | No |
Endpoints
List Rooms
Get all public rooms and private rooms visible to the authenticated user (if provided).
GET /api/rooms?username=alice
Query Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
username | string | No | Legacy compatibility query param (visibility still comes from auth token when present) |
{
"rooms": [
{
"id": "general",
"name": "General Chat",
"type": "public",
"createdAt": 1704067200000,
"userCount": 15
},
{
"id": "abc123",
"name": "Private Room",
"type": "private",
"members": ["alice", "bob"],
"createdAt": 1704153600000,
"userCount": 2
}
]
}
Create Room
Create a new chat room. Requires authentication.
Notes:
- Public room creation is admin-only (
ryo). - Private room creation requires at least one member; creator is auto-included.
POST /api/rooms
Authorization: Bearer {token}
X-Username: alice
Content-Type: application/json
{
"type": "private",
"members": ["alice", "bob"],
"name": "Project Discussion" // optional
}
Request Body:
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | "public" or "private" |
members | string[] | For private | List of usernames |
name | string | Public | Public room name (private names are generated) |
{
"room": {
"id": "abc123def456",
"name": "@alice, @bob",
"type": "private",
"members": ["alice", "bob"],
"createdAt": 1704067200000,
"userCount": 2
}
}
Get Room
Get details for a specific room.
GET /api/rooms/{id}
Response (200):
{
"room": {
"id": "general",
"name": "General Chat",
"type": "public",
"createdAt": 1704067200000,
"userCount": 15
}
}
Delete Room
Delete a room.
- Public rooms: admin-only (
ryo).
- Private rooms: members can "delete" by leaving; room is removed automatically when <= 1 members remain.
DELETE /api/rooms/{id}
Authorization: Bearer {token}
X-Username: alice
Response (200):
{
"success": true
}
Join Room
Join a room to participate in chat.
POST /api/rooms/{id}/join
Authorization: Bearer {token}
X-Username: alice
Content-Type: application/json
{
"username": "alice"
}
Response (200):
{
"success": true
}
Leave Room
Leave a room.
POST /api/rooms/{id}/leave
Authorization: Bearer {token}
X-Username: alice
Content-Type: application/json
{
"username": "alice"
}
Response (200):
{
"success": true
}
List Active Users
Get list of users currently active in a room.
GET /api/rooms/{id}/users
Response (200):
{
"users": [
{
"username": "alice",
"joinedAt": 1704067200000
},
{
"username": "bob",
"joinedAt": 1704153600000
}
]
}
Room Types
Public Rooms
- Visible to all users in room listings
- Anyone can join without invitation
- Default room type for general discussions
Private Rooms
- Only visible to members
- Created with a specific member list
- Ideal for direct messages or group chats
Error Responses
| Status | Error | Description |
|---|---|---|
| 400 | Invalid request | Missing or invalid parameters |
| 401 | Authentication required | Token missing or invalid |
| 403 | Forbidden | Not authorized to perform action (admin/member checks) |
| 404 | Room not found | Room ID doesn't exist |
| 429 | Rate limit exceeded | Too many requests |
Related
- Auth API - Authentication endpoints
- Messages API - Message endpoints
- Presence API - Presence tracking