API

Free Comment Mock REST API Documentation

Free Comment Mock REST API Documentation
117 views
3 min read
#API

The MockX Comment API offers developers the ability to manage comments on posts, facilitating user engagement and content interaction within applications. This guide outlines how to use the API to perform operations such as retrieving, adding, updating, and deleting comments.

Endpoints Overview

This API provides a comprehensive set of endpoints for comment management:

  • GET /: Retrieves all comments.
  • GET /:id: Fetches a specific comment by ID.
  • GET /post/:postId: Retrieves all comments associated with a specific post.
  • POST /add: Adds a new comment.
  • PUT /:id: Updates an entire comment by ID.
  • PATCH /:id: Partially updates a comment by ID.
  • DELETE /:id: Deletes a comment by ID.

Get All Comments

Fetch a list of all comments across all posts.

GET https://api.mockx.net/comments

Parameters:

limit: Limits the number of comments returned. skip: Skips a specified number of comments. Example Response:

{
  "comments": [
    {
      "id": 1,
      "body": "Absolutely love this!",
      "postId": 101,
      "user": {
        "id": 101,
        "username": "NatureLover101"
      }
    }, ...
  ],
  "total": 1000,
  "skip": 0,
  "limit": 20
}

Get Comment by ID

Retrieve detailed information about a specific comment.

GET https://api.mockx.net/comments/{id}

Parameters:

id: The unique identifier of the comment. Example Response:

{
    "id": 1,
    "body": "Absolutely love this!",
    "postId": 101,
    "user": {
        "id": 101,
        "username": "NatureLover101"
    }
}

Get Comments by Post ID

Fetch all comments associated with a specific post.

GET https://api.mockx.net/comments/post/{postId}

Parameters:

postId: The unique identifier of the post. Example Response:

{
    "comments": [
        {
            "id": 1,
            "body": "Absolutely love this!",
            "postId": 101,
            "user": {
                "id": 101,
                "username": "NatureLover101"
            }
        },
        {
            "id": 92,
            "body": "Reading this was the highlight of my day.",
            "postId": 101,
            "user": {
                "id": 142,
                "username": "PoetryAficionado142"
            }
        },
        {
            "id": 267,
            "body": "A well-rounded and deep dive into the subject.",
            "postId": 101,
            "user": {
                "id": 117,
                "username": "LanguageLearner117"
            }
        },
        {
            "id": 312,
            "body": "This contribution is nothing short of brilliant.",
            "postId": 101,
            "user": {
                "id": 112,
                "username": "FashionForward112"
            }
        }
    ],
    "total": 4,
    "skip": 0,
    "limit": 4
}

Add New Comment

Add a new comment to a post.

POST https://api.mockx.net/comments/add

Body: Include the post ID, user ID, and body of the comment in the request body.

{
  "body": "Absolutely love this!",
  "postId": 101,
  "userId": 1
}

Example Response:

{
    "id": 341,
    "body": "Absolutely love this!",
    "postId": 101,
    "user": {
        "id": 1,
        "username": "user0"
    }
}

Update Comment by ID

Modify the details of an existing comment.

PUT https://api.mockx.net/comments/{id}

Parameters:

id: The unique identifier of the comment to be updated. Body: Include the updated comment details in the request body.

{
  "body": "Absolutely love this!",
  "postId": 101,
  "userId": 1
}

Example Response:

{
    "id": 341,
    "body": "Absolutely love this!",
    "postId": 101,
    "user": {
        "id": 1,
        "username": "user0"
    }
}

Delete Comment by ID

Remove a comment from a post.

DELETE https://api.mockx.net/comments/{id}

Parameters:

id: The unique identifier of the comment to be deleted. Example Response:

{
  "message": "Comment with id '{id}' successfully deleted."
}
MockX offers free, reliable mock APIs for easy testing and development, ideal for developers seeking to enhance their workflow without the complexities of setting up any server.
Copyright © 2024. Made with ♥ by MockX.net