Skip to content

Comments

The Comments resource represents user comments on posts. Each comment belongs to a specific post and includes the commenter's name and email.

Base URL

bash
https://api.jsonplaceholder.dev
bash
http://localhost:3000

Schema

typescript
interface Comment {
  id: number
  postId: number
  name: string
  email: string
  body: string
}

Endpoints

Get All Comments

bash
GET /comments

Response:

json
[
  {
    "postId": 1,
    "id": 1,
    "name": "id labore ex et quam laborum",
    "email": "[email protected]",
    "body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
  }
  // ... 499 more comments
]

Get Comments by Post

bash
GET /comments?postId={postId}

Parameters:

  • postId (number, query) - Filter comments by post ID

Response:

json
[
  {
    "postId": 1,
    "id": 1,
    "name": "id labore ex et quam laborum",
    "email": "[email protected]",
    "body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
  }
  // ... more comments for post 1
]

Get Single Comment

bash
GET /comments/{id}

Parameters:

  • id (number) - Comment ID

Response:

json
{
  "postId": 1,
  "id": 1,
  "name": "id labore ex et quam laborum",
  "email": "[email protected]",
  "body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
}

Create Comment

bash
POST /comments

Request Body:

json
{
  "postId": 1,
  "name": "Great post!",
  "email": "[email protected]",
  "body": "This is a great post, thanks for sharing!"
}

Response: 201 Created

json
{
  "id": 501,
  "postId": 1,
  "name": "Great post!",
  "email": "[email protected]",
  "body": "This is a great post, thanks for sharing!"
}

Update Comment (Full Replace)

bash
PUT /comments/{id}

Parameters:

  • id (number) - Comment ID

Request Body:

json
{
  "postId": 1,
  "name": "Updated comment title",
  "email": "[email protected]",
  "body": "Updated comment content"
}

Response: 200 OK

json
{
  "id": 1,
  "postId": 1,
  "name": "Updated comment title",
  "email": "[email protected]",
  "body": "Updated comment content"
}

Update Comment (Partial)

bash
PATCH /comments/{id}

Parameters:

  • id (number) - Comment ID

Request Body: Partial comment object

json
{
  "body": "Just updating the comment text"
}

Response: 200 OK - Updated comment object

Delete Comment

bash
DELETE /comments/{id}

Parameters:

  • id (number) - Comment ID

Response: 200 OK

json
{}

Examples

javascript
// Get all comments
const comments = await fetch('http://localhost:3000/comments')
  .then(res => res.json());

// Get comments by post
const postComments = await fetch('http://localhost:3000/comments?postId=1')
  .then(res => res.json());

// Create new comment
const newComment = await fetch('http://localhost:3000/comments', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    postId: 1,
    name: 'Amazing insight!',
    email: '[email protected]',
    body: 'This post really helped me understand the concept better.'
  })
}).then(res => res.json());

// Update comment
const updatedComment = await fetch('http://localhost:3000/comments/1', {
  method: 'PATCH',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    body: 'Updated my thoughts on this topic.'
  })
}).then(res => res.json());
bash
# Get all comments
curl http://localhost:3000/comments

# Get comments by post
curl http://localhost:3000/comments?postId=1

# Create new comment
curl -X POST http://localhost:3000/comments \
  -H "Content-Type: application/json" \
  -d '{
    "postId": 1,
    "name": "Amazing insight!",
    "email": "[email protected]",
    "body": "This post really helped me understand the concept better."
  }'

# Update comment
curl -X PATCH http://localhost:3000/comments/1 \
  -H "Content-Type: application/json" \
  -d '{"body": "Updated my thoughts on this topic."}'

# Delete comment
curl -X DELETE http://localhost:3000/comments/1
python
import requests

# Get all comments
comments = requests.get('http://localhost:3000/comments').json()

# Get comments by post
post_comments = requests.get('http://localhost:3000/comments?postId=1').json()

# Create new comment
new_comment = requests.post('http://localhost:3000/comments', json={
    'postId': 1,
    'name': 'Amazing insight!',
    'email': '[email protected]',
    'body': 'This post really helped me understand the concept better.'
}).json()

# Update comment
updated_comment = requests.patch('http://localhost:3000/comments/1', json={
    'body': 'Updated my thoughts on this topic.'
}).json()

# Delete comment
requests.delete('http://localhost:3000/comments/1')
  • Posts - The post this comment belongs to
  • Users - While not directly linked, comments are typically from users

Fast Fake REST API powered by Bun + Elysia.js | Documentation site source: github.com/ckissi/jsonplaceholder