Docs
You can use examples below to check how DummyJSON works.
Posts
Get all posts
Show outputfetch('https://dummyjson.com/posts') .then(res => res.json()) .then(console.log);
Get a single post
Show outputfetch('https://dummyjson.com/posts/1') .then(res => res.json()) .then(console.log);
Search posts
Show outputfetch('https://dummyjson.com/posts/search?q=love') .then(res => res.json()) .then(console.log);
Limit and skip posts
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/posts?limit=10&skip=10&select=title,reactions,userId') .then(res => res.json()) .then(console.log);
Get all posts by user id
Show output/* getting posts of user with id 5 */ fetch('https://dummyjson.com/posts/user/5') .then(res => res.json()) .then(console.log);
Get post's comments
Show output/* getting comments of posts id 1 */ fetch('https://dummyjson.com/posts/1/comments') .then(res => res.json()) .then(console.log);
Add a new post
Adding a new post will not add it into the server.
It will simulate a POST request and will return the new created
post with a new id
Show outputfetch('https://dummyjson.com/posts/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: 'I am in love with someone.', userId: 5, /* other post data */ }) }) .then(res => res.json()) .then(console.log);
Update a post
Updating a post will not update it into the server.
It will simulate a PUT/PATCH request and will return the post with
modified data
Show output/* updating title of post with id 1 */ fetch('https://dummyjson.com/posts/1', { method: 'PUT', /* or PATCH */ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: 'I think I should shift to the moon', }) }) .then(res => res.json()) .then(console.log);
Delete a post
Deleting a post will not delete it into the server.
It will simulate a DELETE request and will return deleted post
with "isDeleted" & "deletedOn" keys
Show outputfetch('https://dummyjson.com/posts/1', { method: 'DELETE', }) .then(res => res.json()) .then(console.log);