API

Free Post Mock REST API Documentation

Free Post Mock REST API Documentation
117 views
4 min read
#API

The MockX Post API provides a comprehensive suite of functionalities for managing blog posts within your applications. From posting new content to engaging with user comments, this API covers all necessary operations to enhance your content management system.

Endpoints Overview

The Post API includes endpoints for various post-related operations:

  • GET /: Retrieves all posts.
  • **GET /search: Searches for posts based on query parameters.
  • GET /:id: Fetches a specific post by ID.
  • GET /user/:userId: Retrieves all posts created by a specific user.
  • GET /:postId/comments: Fetches all comments associated with a specific post.
  • POST /add: Adds a new post.
  • PUT /:id: Updates an entire post by ID.
  • PATCH /:id: Partially updates a post by ID.
  • DELETE /:id: Deletes a post by ID.

Get All Posts

Fetch a comprehensive list of all posts.

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

Parameters:

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

{
  "posts": [
       {
            "id": 1,
            "title": "Realm of Shadows",
            "body": "The breaking dawn was not just the start of a new day, but a new chapter waiting to be written.",
            "userId": 42,
            "tags": [
                "mathematics",
                "statistics"
            ],
            "reactions": 3
        }
  ],
  "total": 300,
  "skip": 0,
  "limit": 20
}

Search Posts

Search for posts based on a query parameter. It will search body of the post for that query.

GET https://api.mockx.net/posts/search?q=dawn

Parameters:

q: The search query. Example Response:

{
  "posts": [
     {
            "id": 87,
            "title": "Lost in the Echo",
            "body": "The journey began at dawn, with every step leading towards discoveries that would change their understanding of the world.",
            "userId": 65,
            "tags": [
                "history",
                "cultural studies"
            ]
     },
     ...
  ],
  "total": 15,
  "skip": 0,
  "limit": 15
}

Get Post by ID

Retrieve detailed information about a specific post.

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

Parameters:

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

{
    "id": 1,
    "title": "Realm of Shadows",
    "body": "The breaking dawn was not just the start of a new day, but a new chapter waiting to be written.",
    "userId": 42,
    "tags": [
        "mathematics",
        "statistics"
    ],
    "reactions": 3
}

Get Posts by User ID

Fetch all posts created by a specific user.

GET https://api.mockx.net/posts/user/{userId}

Example :

GET https://api.mockx.net/posts/user/42

Parameters:

userId: The unique identifier of the user. Example Response:

{
  "posts": [
    {
      "id": 1,
      "title": "Realm of Shadows",
      "body": "The breaking dawn was not just the start of a new day, but a new chapter waiting to be written.",
      "userId": 42,
      "tags": [
        "mathematics",
        "statistics"
      ],
      "reactions": 3
    },
    ...
  ]
}

Get Comments by Post ID

Retrieve all comments associated with a specific post.

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

Example :

GET https://api.mockx.net/posts/12/comments
### Parameters:

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

{
  "comments": [
    {
      "id": 195,
      "body": "A refreshing take that challenges conventional wisdom.",
      "postId": 12,
      "user": {
        "id": 145,
        "username": "VintageCollector145"
      }
    },
    ...
  ]
}

Add New Post

Add a new post to the system.

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

Body: Include the title, body, user ID, tags, and reactions in the request body.

{
  "title": "Realm of Shadows",
  "body": "The breaking dawn was not just the start of a new day, but a new chapter waiting to be written.",
  "userId": 42,
  "tags": [
    "mathematics",
    "statistics"
  ],
  "reactions": 3
}

Example Response:

{
    "id": 151,
    "title": "Realm of Shadows",
    "body": "The breaking dawn was not just the start of a new day, but a new chapter waiting to be written.",
    "userId": 42,
    "tags": [
        "mathematics",
        "statistics"
    ],
    "reactions": 3
}

Update Post by ID

Modify the details of an existing post.

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

Example :

PUT http://localhost:8080/posts/12

Parameters:

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

Example Response:

{
    "id": 12,
    "title": "Realm of Shadows",
    "body": "The breaking dawn was not just the start of a new day, but a new chapter waiting to be written.",
    "userId": 42,
    "tags": [
        "mathematics",
        "statistics"
    ],
    "reactions": 3
}

Delete Post by ID

Remove a post from the system.

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

Parameters:

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

{
  "message": "Post 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