📚 Forum API Documentation

Complete REST API documentation for Forum application

Base URL

https://api.forum.gutsylab.com/api

Authentication

This API uses Laravel Sanctum for authentication. After login/register, include the token in the header:

Authorization: Bearer {your_token}

🔐 Authentication

POST /auth/register

Register a new user account

Request Body:

{
  "name": "John Doe",
  "username": "johndoe",
  "email": "john@example.com",
  "password": "password123",
  "password_confirmation": "password123"
}

Response (201):

{
  "success": true,
  "message": "User registered successfully",
  "data": {
    "user": {
      "id": 1,
      "name": "John Doe",
      "username": "johndoe",
      "email": "john@example.com"
    },
    "access_token": "1|abc123..."
  }
}
POST /auth/login

Login to existing account

Request Body:

{
  "email": "john@example.com",
  "password": "password123"
}

Response (200):

{
  "success": true,
  "message": "Login successful",
  "data": {
    "user": {
      "id": 1,
      "name": "John Doe",
      "username": "johndoe",
      "email": "john@example.com"
    },
    "access_token": "2|xyz789..."
  }
}
POST /auth/logout
Authentication Required

Logout from current session

Headers:

Authorization: Bearer {token}

Response (200):

{
  "success": true,
  "message": "Logout successful"
}

📝 Topics

GET /topics
Authentication Required

Get all topics with pagination

Query Parameters:

page (optional): Page number for pagination

Response (200):

{
  "success": true,
  "data": {
    "current_page": 1,
    "data": [
      {
        "id": 1,
        "title": "Laravel Best Practices",
        "body": "What are the best practices...",
        "user": {
          "id": 1,
          "name": "John Doe"
        },
        "category": {
          "id": 1,
          "name": "Laravel"
        },
        "comments_count": 5,
        "likes_count": 10
      }
    ],
    "per_page": 20,
    "total": 50
  }
}
POST /topics
Authentication Required

Create a new topic. Category will be created automatically if not exists.

Request Body:

{
  "title": "Laravel Best Practices",
  "body": "What are the best practices when using Laravel?",
  "category_name": "Laravel"
}

Response (201):

{
  "success": true,
  "message": "Topic created successfully",
  "data": {
    "id": 1,
    "title": "Laravel Best Practices",
    "body": "What are the best practices...",
    "user_id": 1,
    "topic_category_id": 1
  }
}
GET /topics/{id}
Authentication Required

Get detailed information about a specific topic

Response (200):

{
  "success": true,
  "data": {
    "id": 1,
    "title": "Laravel Best Practices",
    "body": "What are the best practices...",
    "user": {...},
    "category": {...},
    "comments": [...],
    "comments_count": 5,
    "likes_count": 10
  }
}
PUT /topics/{id}
Authentication Required

Update a topic. Only the owner can update their topic.

Request Body:

{
  "title": "Updated Title",
  "body": "Updated body content",
  "category_name": "PHP"
}

Response (200):

{
  "success": true,
  "message": "Topic updated successfully",
  "data": {...}
}
DELETE /topics/{id}
Authentication Required

Delete a topic. Only the owner can delete their topic.

Response (200):

{
  "success": true,
  "message": "Topic deleted successfully"
}

💬 Comments

GET /topics/{topicId}/comments
Authentication Required

Get all comments for a specific topic

Response (200):

{
  "success": true,
  "data": {
    "current_page": 1,
    "data": [
      {
        "id": 1,
        "topic_id": 1,
        "user_id": 2,
        "body": "Great question!",
        "user": {
          "id": 2,
          "name": "Jane Doe"
        }
      }
    ]
  }
}
POST /topics/{topicId}/comments
Authentication Required

Create a new comment on a topic

Request Body:

{
  "body": "This is a great topic!"
}

Response (201):

{
  "success": true,
  "message": "Comment created successfully",
  "data": {
    "id": 1,
    "topic_id": 1,
    "body": "This is a great topic!",
    "user": {...}
  }
}
PUT /topics/{topicId}/comments/{commentId}
Authentication Required

Update a comment. Only the owner can update their comment.

Request Body:

{
  "body": "Updated comment text"
}
DELETE /topics/{topicId}/comments/{commentId}
Authentication Required

Delete a comment. Only the owner can delete their comment.

❤️ Likes

POST /topics/{topicId}/like
Authentication Required

Toggle like/unlike on a topic

Response (200):

{
  "success": true,
  "message": "Topic liked successfully",
  "data": {
    "liked": true,
    "likes_count": 11
  }
}
GET /topics/{topicId}/likes
Authentication Required

Get list of users who liked a topic

Response (200):

{
  "success": true,
  "data": {
    "data": [
      {
        "id": 2,
        "name": "Jane Doe",
        "username": "janedoe"
      }
    ]
  }
}

👥 Users

GET /users/search
Authentication Required

Search users by username, email, or name

Query Parameters:

query (required): Search term
page (optional): Page number

Example:

GET /users/search?query=john
GET /users/{id}
Authentication Required

Get user profile with stats

Response (200):

{
  "success": true,
  "data": {
    "id": 1,
    "name": "John Doe",
    "username": "johndoe",
    "topics_count": 15,
    "followers_count": 20,
    "following_count": 10,
    "is_following": false
  }
}
POST /users/{id}/follow
Authentication Required

Follow a user

Response (200):

{
  "success": true,
  "message": "User followed successfully"
}
DELETE /users/{id}/follow
Authentication Required

Unfollow a user

GET /users/{id}/followers
Authentication Required

Get list of user's followers

GET /users/{id}/following
Authentication Required

Get list of users that this user is following

📌 Important Notes

  • All endpoints requiring authentication must include Authorization: Bearer {token} header
  • Default pagination is 20 items per page
  • Only topic/comment owners can update or delete their content
  • Categories are automatically created when creating a topic
  • Like endpoint uses toggle mechanism (same endpoint for like/unlike)
  • Users cannot follow themselves
  • Search excludes the currently logged-in user