cpfergus1 / zylytyPractice

0 stars 1 forks source link

Web Forum API Documentation

Introduction

This documentation provides all the necessary information to get started with the Web Forum API. It includes instructions for setting up the environment, detailed descriptions of each endpoint, and how to use them effectively to build and manage a web forum.

Setup

Prerequisites

Before you begin, ensure you have the following installed:

Installation

Follow these steps to get your application running:

  1. Clone the Repository

    Use Git to clone the source code to your local machine.

    git clone <REPOSITORY_SSH_URL>
  2. Build the Docker Image

    Navigate to the project directory and build the Docker image.

    cd <PROJECT_DIRECTORY>
    docker build -t web-forum-api .
  3. Run the Container

    Start the application by running the Docker container.

    docker run -p <API_LISTENING_PORT>:<API_LISTENING_PORT> web-forum-api

API Endpoints

User Registration Endpoint

Endpoint: POST /user/register

Description: Allows new users to register to the web forum by providing a username, password, and email.

Request Body:

{
  "username": "newUser123",
  "password": "userPassword123",
  "email": "newuser123@example.com"
}

Response Codes:

Login Endpoint

Endpoint: POST /user/login

Description: Authenticates users by verifying their credentials and initiates a session.

Request Body:

{
  "username": "existingUser",
  "password": "userPassword123"
}

Successful Response:

Error Handling:

List and Create Categories Endpoint

Create Categories

Endpoint: POST /categories

Description: Allows for the creation of new categories within the forum. Requires an admin API key for authentication.

Headers: Token: <admin_api_key>

Request Body:

{
  "categories": ["Technology", "Health"]
}

Response Codes:

List Categories

Endpoint: GET /categories

Description: Retrieves a list of all forum categories, including the default "Default" category.

Successful Response:

Error Handling:

Filter and Create Threads Endpoint

Create Thread

Endpoint: POST /thread

Description: Enables authenticated users to create a new thread within a specified category.

Request Body:

{
  "category": "Default",
  "title": "Exciting Discussion",
  "openingPost": {
    "text": "Let's talk about something exciting!"
  }
}

Response Codes:

List Threads

Endpoint: GET /thread

Description: Allows users to retrieve a list of threads filtered by categories, authors, or sorting preferences.

Query Parameters: categories=Default&newest_first=true&page=0&page_size=10

Successful Response:

Error Handling:

Get and Create Thread Posts Endpoint

Add Posts

Endpoint: POST /thread/post

Description: Allows authenticated users to add one or more posts to an existing thread.

Request Body:

{
  "threadId": 1,
  "posts": [
    {"text": "I completely agree with this point!"},
    {"text": "Here's an interesting fact that might add to the discussion..."}
  ]
}

Response Codes:

Get Posts

Endpoint: GET /thread/post

Description: Retrieves all posts within a specified thread, facilitating continuous conversation flow.

Query Parameters: thread_id=1

Successful Response:

Search Endpoint

Endpoint: GET /search

Description: Enables users to search for threads containing specific text, improving discoverability and user engagement.

Query Parameters: text=but smith was actually a banana

Successful Response:

Delete Thread Endpoint

Endpoint: DELETE /thread

Description: Allows administrators to remove threads, maintaining content quality and relevancy.

Query Parameters: id=2

Headers: Token: <admin_api_key>

Response Codes:

Delete Categories Endpoint

Endpoint: DELETE /categories

Description: Enables forum administration to dynamically manage forum categories.

Query Parameters: category=Tech

Headers: Token: <admin_api_key>

Response Codes:

Import Users via CSV Endpoint

Endpoint: POST /csv

Description: Facilitates bulk user registration through CSV file uploads, streamlining the onboarding process for administrators.

Headers: Token: <admin_api_key>, Content-Type: text/csv

Request Body: CSV content following the format username,password,email.

Successful Response:

Error Handling:

Environment Variables

The application requires the following environment variables for configuration:

Additional Notes