Skip to content
SciTechMC edited this page Feb 10, 2025 · 4 revisions

Public API Documentation

Overview

  • Script Name: ChatCLI
  • Description: Command-line chat application for real-time messaging and account management.
  • Base URLs:
    • https://chat.puam.be/
    • wss://fortbow.duckdns.org:8765/

Authentication

  • Type: Session Token
  • Instructions: After logging in, the server returns a session token that must be sent with each request for secure access.

Endpoints

1. Verify Connection

  • URL: /verify-connection
  • Method: POST, GET
  • Description: Verifies server connection and checks client version.

Request

  • Payload:

    {
      "version": "alpha 0.2.0"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": "Hello World!"
    }
  • Error (400 Bad Request):

    {
      "error": "Invalid request!"
    }
  • Error (405 Method Not Allowed):

    {
      "error": "Unsupported HTTP method!"
    }

2. Register

  • URL: /register
  • Method: POST
  • Description: Registers a new user with a username, password, and email. A verification code is sent to the user's email for confirmation.

Request

  • Payload:

    {
      "username": "exampleuser",
      "password": "Password123!",
      "email": "user@example.com"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": "Email sent successfully"
    }
    • The user receives an email with a verification code to complete the registration process.
  • Error (400 Bad Request):

    {
      "error": "Username and password are required"
    }
  • Error (500 Internal Server Error):

    {
      "error": "Database error: {error message}"
    }

3. Login

  • URL: /login
  • Method: POST
  • Description: Logs in a user by validating credentials and generating a session token.

Request

  • Payload:

    {
      "username": "exampleuser",
      "password": "Password123!"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": "Login Successful!",
      "session_token": "randomSessionToken"
    }
  • Error (400 Bad Request):

    {
      "error": "Invalid password"
    }
  • Error (404 Not Found):

    {
      "error": "Username not found!"
    }

4. Reset Password Request

  • URL: /reset-password-request
  • Method: POST
  • Description: Sends a password reset email with a unique reset token.

Request

  • Payload:

    {
      "data": "user@example.com"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": "Password reset request initiated. Please check your email."
    }
  • Error (404 Not Found):

    {
      "error": "User not found"
    }

5. Reset Password

  • URL: /reset-password
  • Method: GET, POST
  • Description: Resets the user's password using the token received in the reset email.

GET Request

  • Query Parameters:
    • token: The reset token
    • username: The username

POST Request

  • Payload:
    {
      "password": "NewPassword123!",
      "confirm_password": "NewPassword123!"
    }

Response

  • Success (200 OK):

    {
      "message": "Password reset successfully"
    }
  • Error (400 Bad Request):

    {
      "error": "Passwords do not match"
    }

6. Fetch Chats

  • URL: /fetch-chats
  • Method: POST
  • Description: Retrieves a list of users the current user has active chats with.

Request

  • Payload:

    {
      "username": "exampleuser",
      "session_token": "sessionToken123"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": ["user1", "user2"]
    }
  • Error (400 Bad Request):

    {
      "error": "Unable to verify user!"
    }

7. Create Chat

  • URL: /create-chat
  • Method: POST
  • Description: Creates a new chat between two users.

Request

  • Payload:

    {
      "username": "exampleuser",
      "receiver": "anotheruser",
      "session_token": "sessionToken123"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": "Chat created successfully!"
    }
  • Error (400 Bad Request):

    {
      "error": "Sender or receiver not found!"
    }

8. Receive Message

  • URL: /receive-message
  • Method: POST
  • Description: Stores a message sent from one user to another.

Request

  • Payload:

    {
      "username": "exampleuser",
      "receiver": "anotheruser",
      "session_token": "sessionToken123",
      "message": "Hello, how are you?"
    }
  • Query Parameters:
    None

Response

  • Success (200 OK):

    {
      "response": "Message sent successfully!"
    }
  • Error (400 Bad Request):

    {
      "error": "No chat found between users!"
    }

9. Subscribe for Notifications

  • URL: /subscribe
  • Method: POST
  • Description: Subscribes the user to receive notifications about future releases.

Request

  • Form submission with email as the input field.

Response

  • Success (200 OK):

    {
      "response": "You have successfully subscribed!"
    }
  • Error (400 Bad Request):

    {
      "error": "Email is required"
    }

Error Codes

  • 400: Bad request (e.g., missing fields)
  • 401: Unauthorized (e.g., invalid session token)
  • 404: Not found (e.g., username or chat not found)
  • 500: Internal server error (unexpected failure)

Clone this wiki locally