Skip to content

API Documentation

dascher edited this page Mar 27, 2024 · 10 revisions

API Documentation

Welcome to the API documentation for our project. Here you will find detailed information about the available API endpoints, including request methods, required parameters, and sample responses.

Base URL

All API requests should be made to the base URL: https://localhost:8000/api

Endpoints

Add Stream

Adds a stream to the server.

HTTP Request

POST /stream/add

Request Body

{
    "userId": "1",
    "title": "Sample Stream",
    "description": "This is a sample description",
    "photo": "https://example.com/photo.jpg"
}

Success Response

  • Code: 201 Created
  • Content:
{
    "success": true,
    "data": {
        "streamId": 1
    }
}

Error Response

  • Code: 500 Internal Server Error
  • Content:
{
    "success": false,
    "error": "Error: Message"
}

Search Streams

Searches for streams based on a keyword in the title or description.

HTTP Request

GET /stream/search

Query Parameters

  • keyword (string): Required. The keyword to search for in the stream titles and descriptions.

Example request URL: /api/stream/search?keyword=sample

Success Response

  • Code: 200 OK
  • Content:
{
    "success": true,
    "data": {
        {
          "id": 1,
          "user_id": 1,
          "title": "Sample Stream",
          "description": "This is a sample stream description.",
          "photo": "https://example.com/photo.jpg",
          "start_time": "2024-02-20T17:21:44.000Z",
          "is_active": true
        },
        {
          "id": 2,
          "user_id": 2,
          "title": "Another Sample Stream",
          "description": "This is another sample stream description.",
          "photo": "https://example.com/another_photo.jpg",
          "start_time": "2024-02-21T17:21:44.000Z",
          "is_active": true
        }
    }
}

Error Response

  • Code: 500 Internal Server Error
  • Content:
{
    "success": false,
    "error": "Error: Message"
}

Get Stream by ID

Searches for streams based on a its ID.

HTTP Request

GET /stream/get

URL Parameters

  • streamId (int): Required. ID of the stream.

Example request URL: /api/stream/get/1

Success Response

  • Code: 200 OK
  • Content:
{
    "succes": true,
    "data": {
        {
            "id": 1,
            "user_id": 1,
            "title": "Sample Stream",
            "description": "This is a sample stream description.",
            "photo": "https://example.com/photo.jpg",
            "start_time": "2024-02-20T17:21:44.000Z",
            "is_active": true
        }
    }
}

Error Response

  • Code: 500 Internal Server Error
  • Content:
{
    "success": false,
    "error": "Error: Message"
}

Register User

Registers a user in the user management system.

HTTP Request

POST /auth/register

Request Body

{
    "username": "example_user",
    "email": "example@email.com",
    "password": "password"
}

Success Response

  • Code: 201 Created
  • Content:
{
    "success": true,
    "data": {
        "userId": 1
    }
}

Error Response

  • Code: 500 Internal Server Error
  • Content:
{
    "success": false,
    "error": "Error: Message"
}

Login User

Login User to the user management system.

HTTP Request

POST /auth/login

Request Body

{
    "username": "example_user",
    "password": "password"
}

Success Response

  • Code: 200 OK
  • Content:
{
    "success": true,
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
    }
}

Error Response

  • Code: 500 Internal Server Error
  • Content:
{
    "success": false,
    "error": "Error: Message"
}

Fetch Chat History

Retrieves the chat history for a specific stream.

HTTP Request

GET /chat/messages/:streamId

URL Parameters

  • streamId (int): Required. ID of the stream for which to fetch chat history.

Success Response

  • Code: 200 OK
  • Content:
{
    "success": true,
    "data": {
        {
            "id": 1,
            "user_id": 2,
            "stream_id": 1,
            "body": "Hello, world!",
            "timestamp": "2024-02-20T17:21:44.000Z"
        },
        {
            "id": 2,
            "user_id": 2,
            "stream_id": 1,
            "body": "This is a test message.",
            "timestamp": "2024-02-20T17:21:44.000Z"
        }
    }
}

Error Response

  • Code: 500 Internal Server Error
  • Content:
{
    "success": false,
    "error": "Error: Message"
}

Add Message

Allows a user to send a message in a chat stream via WebSocket using Socket.IO.

WebSocket Event to Emit

Event Name: newMessage
Emit Payload:
{
    "userId": 1,
    "streamId": 1,
    "message": "Hello, this is a test message!"
}

Recieve information from federation member

Receive data from the members of the federation involving the live stream status.

HTTP Request

POST /api/fed/fedeIn

Body of HTTP Request

{
    "fedID": Int fedID
}

Success response

code: 200

Error response

code: 500