Comments

This section describes the endpoints for managing comments on posts.

Comment Model

The Comment object represents a comment on a post. Comments can be nested.

Comment Object
{
    "id": 0,
    "post_id": 0,
    "user_id": 0,
    "parent_id": 0,
    "content": "string",
    "comment_date": 0,
    "likes": 0,
    "likers": [0],
    "replies": []
}

Endpoints

/posts/{id}/comments [GET]

Get all comments for a specific post, sorted by date. The comments are returned as a tree structure.

Return Example

200 OK
[
    {
        "id": 1,
        "post_id": 1,
        "user_id": 2,
        "parent_id": null,
        "content": "Awesome, congrats on the launch!",
        "comment_date": 1752891000,
        "likes": 2,
        "likers": [1, 3],
        "replies": [
            {
                "id": 3,
                "post_id": 1,
                "user_id": 4,
                "parent_id": 1,
                "content": "I agree!",
                "comment_date": 1752891200,
                "likes": 1,
                "likers": [2],
                "replies": []
            }
        ]
    }
]
* /posts/{id}/comments [POST]

Create a new comment on a post. To reply to another comment, include the parent_id.

Request Example

Body
{
    "content": "This is a new comment.",
    "parent_id": null
}

Return Example

201 Created
{
    "id": 35,
    "post_id": 1,
    "user_id": 1,
    "parent_id": null,
    "content": "This is a new comment.",
    "comment_date": 1752894500,
    "likes": 0,
    "likers": null,
    "replies": []
}
* /comments/{id}/like [POST]

Like a comment by its ID.

* /comments/{id}/unlike [POST]

Remove a like from a comment by its ID.

* /comments/{id}/haveiliked [GET]

Check if the authenticated user has liked a comment.

Return Example

200 OK
{
    "liked": false
}

Last updated