Skip to content

API Overview

Max Azatian edited this page Oct 5, 2024 · 1 revision

Authentication (/auth)

  • POST /login: Authenticate a user and return access and refresh tokens
  • POST /register: Register a new user
  • POST /refresh: Refresh an access token using a refresh token
  • POST /logout: Invalidate the current access token

Users (/users)

  • GET /: List all users (with pagination and filtering)
  • GET /me: Get the current user's profile
  • PUT /me: Update the current user's profile
  • DELETE /me: Delete the current user's account
  • GET /search: Search for users by username

Chats (/chats)

  • POST /: Create a new chat
  • GET /: List all chats for the current user (with pagination and filtering)
  • POST /start: Start a new chat with another user
  • GET /{chat_id}: Get details of a specific chat
  • PUT /{chat_id}: Update a chat's details
  • DELETE /{chat_id}: Delete a chat
  • GET /{chat_id}/members: List members of a chat
  • POST /{chat_id}/members: Add a member to a chat
  • DELETE /{chat_id}/members/{user_id}: Remove a member from a chat
  • GET /{chat_id}/unread_count: Get the count of unread messages in a chat

Messages (/messages)

  • POST /: Create a new message
  • GET /{chat_id}: Get messages for a specific chat (with pagination and filtering)
  • PUT /{message_id}: Update a message
  • DELETE /{message_id}: Delete a message
  • PUT /{message_id}/status: Update the read status of a message

Key Features

  1. Token-based authentication with refresh mechanism
  2. User management (registration, profile updates, deletion)
  3. Chat creation and management
  4. Real-time messaging
  5. Message read status tracking
  6. Unread message count
  7. User search functionality

Authentication

All endpoints, except for login and register, require authentication. The API uses OAuth2 with Bearer tokens. Include the access token in the Authorization header of your requests:

Authorization: Bearer <your_access_token>

Pagination

List endpoints (users, chats, messages) support pagination using skip and limit query parameters.

Filtering

Some list endpoints support filtering:

  • Users can be filtered by username
  • Chats can be filtered by name
  • Messages can be filtered by content

Real-time Updates

The API supports real-time updates through Redis. Events are dispatched for:

  • New messages
  • Message updates
  • Message deletions
  • Message status changes
  • Unread count updates

Error Handling

The API uses standard HTTP status codes for indicating the success or failure of requests. Detailed error messages are provided in the response body for easier debugging and error handling on the client side.

API Versioning

The current version of the API is v1. All endpoints are prefixed with /api/v1/.

For detailed information on request and response formats, please refer to the API documentation available at /docs when running the server.

Clone this wiki locally