Docs
You can use examples below to check how DummyJSON works.
Comments
Get all comments
Show outputfetch('https://dummyjson.com/comments') .then(res => res.json()) .then(console.log);
Get a single comment
Show outputfetch('https://dummyjson.com/comments/1') .then(res => res.json()) .then(console.log);
Limit and skip comments
You can pass "limit" and "skip" params to limit and skip the
results for pagination, and use limit=0 to get all items.
You can pass "select" as query params with comma-separated values
to select specific data.
Show outputfetch('https://dummyjson.com/comments?limit=10&skip=10&select=body,postId') .then(res => res.json()) .then(console.log);
Get all comments by post id
Show output/* getting comments of post with id 5 */ fetch('https://dummyjson.com/comments/post/5') .then(res => res.json()) .then(console.log);
Add a new comment
Adding a new comment will not add it into the server.
It will simulate a POST request and will return the new created
comment with a new id
Show outputfetch('https://dummyjson.com/comments/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ body: 'This makes all sense to me!', postId: 3, userId: 5, }) }) .then(res => res.json()) .then(console.log);
Update a comment
Updating a comment will not update it into the server.
It will simulate a PUT/PATCH request and will return the comment
with modified data
Show output/* updating body of comment with id 1 */ fetch('https://dummyjson.com/comments/1', { method: 'PUT', /* or PATCH */ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ body: 'I think I should shift to the moon', }) }) .then(res => res.json()) .then(console.log);
Delete a comment
Deleting a comment will not delete it into the server.
It will simulate a DELETE request and will return deleted comment
with "isDeleted" & "deletedOn" keys
Show outputfetch('https://dummyjson.com/comments/1', { method: 'DELETE', }) .then(res => res.json()) .then(console.log);