[ { "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]
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]
{ "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"}
// Get all commentsconst comments = await fetch('http://localhost:3000/comments') .then(res => res.json());// Get comments by postconst postComments = await fetch('http://localhost:3000/comments?postId=1') .then(res => res.json());// Create new commentconst 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 commentconst 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 commentscurl http://localhost:3000/comments# Get comments by postcurl http://localhost:3000/comments?postId=1# Create new commentcurl -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 commentcurl -X PATCH http://localhost:3000/comments/1 \ -H "Content-Type: application/json" \ -d '{"body": "Updated my thoughts on this topic."}'# Delete commentcurl -X DELETE http://localhost:3000/comments/1
python
import requests# Get all commentscomments = requests.get('http://localhost:3000/comments').json()# Get comments by postpost_comments = requests.get('http://localhost:3000/comments?postId=1').json()# Create new commentnew_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 commentupdated_comment = requests.patch('http://localhost:3000/comments/1', json={ 'body': 'Updated my thoughts on this topic.'}).json()# Delete commentrequests.delete('http://localhost:3000/comments/1')
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
Schema
Endpoints
Get All Comments
Response:
Get Comments by Post
Parameters:
postId
(number, query) - Filter comments by post IDResponse:
Get Single Comment
Parameters:
id
(number) - Comment IDResponse:
Create Comment
Request Body:
Response:
201 Created
Update Comment (Full Replace)
Parameters:
id
(number) - Comment IDRequest Body:
Response:
200 OK
Update Comment (Partial)
Parameters:
id
(number) - Comment IDRequest Body: Partial comment object
Response:
200 OK
- Updated comment objectDelete Comment
Parameters:
id
(number) - Comment IDResponse:
200 OK
Examples
Related Resources