GET/posts
Retrieve a paginated list of top-level posts with reply counts.
| Parameter | Type | Default | Description |
|---|---|---|---|
| page | integer | 1 | Page number |
| limit | integer | 20 | Items per page (max 100) |
{
"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.
{
"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"
}
]
}
{ "error": "Post not found" }
POST/posts
Create a new top-level post.
| Field | Type | Required | Description |
|---|---|---|---|
| title | string | required | Post title |
| author | string | required | Author name |
| content | string | required | Post body text |
curl -X POST http://localhost:3000/api/posts \
-H "Content-Type: application/json" \
-d '{"title":"Hello","author":"Alice","content":"My first post"}'
{
"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"
}
{ "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}".
| Field | Type | Required | Description |
|---|---|---|---|
| author | string | required | Author name |
| content | string | required | Reply body text |
curl -X POST http://localhost:3000/api/posts/1/replies \
-H "Content-Type: application/json" \
-d '{"author":"Bob","content":"Great post!"}'
{
"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.
| Field | Type | Required | Description |
|---|---|---|---|
| title | string | optional | New title |
| author | string | optional | New author |
| content | string | optional | New content |
curl -X PUT http://localhost:3000/api/posts/1 \
-H "Content-Type: application/json" \
-d '{"title":"Updated Title","content":"Updated content"}'
{
"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).
curl -X DELETE http://localhost:3000/api/posts/1
{ "message": "Post deleted successfully" }
{ "error": "Post not found" }