API Documentation

← Back to Board
Base URL: http://localhost:3000/api

Posts

GET/posts

Retrieve a paginated list of top-level posts with reply counts.

Query Parameters

ParameterTypeDefaultDescription
pageinteger1Page number
limitinteger20Items per page (max 100)

Response 200

{
  "posts": [
    {
      "id": 1,
      "title": "Hello World",
      "author": "Alice",
      "content": "My first post",
      "parent_id": null,
      "created_at": "2026-02-08 12:00:00",
      "updated_at": "2026-02-08 12:00:00",
      "reply_count": 2
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 1,
    "totalPages": 1
  }
}

GET/posts/:id

Retrieve a single post with all its replies.

Response 200

{
  "id": 1,
  "title": "Hello World",
  "author": "Alice",
  "content": "My first post",
  "parent_id": null,
  "created_at": "2026-02-08 12:00:00",
  "updated_at": "2026-02-08 12:00:00",
  "replies": [
    {
      "id": 2,
      "title": "RE: Hello World",
      "author": "Bob",
      "content": "Great post!",
      "parent_id": 1,
      "created_at": "2026-02-08 12:05:00",
      "updated_at": "2026-02-08 12:05:00"
    }
  ]
}

Response 404

{ "error": "Post not found" }

POST/posts

Create a new top-level post.

Request Body (JSON)

FieldTypeRequiredDescription
titlestringrequiredPost title
authorstringrequiredAuthor name
contentstringrequiredPost body text

Example

curl -X POST http://localhost:3000/api/posts \
  -H "Content-Type: application/json" \
  -d '{"title":"Hello","author":"Alice","content":"My first post"}'

Response 201

{
  "id": 1,
  "title": "Hello",
  "author": "Alice",
  "content": "My first post",
  "parent_id": null,
  "created_at": "2026-02-08 12:00:00",
  "updated_at": "2026-02-08 12:00:00"
}

Response 400

{ "error": "title, author, and content are required" }

POST/posts/:id/replies

Create a reply to an existing post. Title is auto-generated as "RE: {parent title}".

Request Body (JSON)

FieldTypeRequiredDescription
authorstringrequiredAuthor name
contentstringrequiredReply body text

Example

curl -X POST http://localhost:3000/api/posts/1/replies \
  -H "Content-Type: application/json" \
  -d '{"author":"Bob","content":"Great post!"}'

Response 201

{
  "id": 2,
  "title": "RE: Hello",
  "author": "Bob",
  "content": "Great post!",
  "parent_id": 1,
  "created_at": "2026-02-08 12:05:00",
  "updated_at": "2026-02-08 12:05:00"
}

PUT/posts/:id

Update an existing post or reply. Only provided fields are updated.

Request Body (JSON)

FieldTypeRequiredDescription
titlestringoptionalNew title
authorstringoptionalNew author
contentstringoptionalNew content

Example

curl -X PUT http://localhost:3000/api/posts/1 \
  -H "Content-Type: application/json" \
  -d '{"title":"Updated Title","content":"Updated content"}'

Response 200

{
  "id": 1,
  "title": "Updated Title",
  "author": "Alice",
  "content": "Updated content",
  "parent_id": null,
  "created_at": "2026-02-08 12:00:00",
  "updated_at": "2026-02-08 12:10:00"
}

DELETE/posts/:id

Delete a post. If deleting a top-level post, all replies are also deleted (cascade).

Example

curl -X DELETE http://localhost:3000/api/posts/1

Response 200

{ "message": "Post deleted successfully" }

Response 404

{ "error": "Post not found" }