Docs
You can use examples below to check how DummyJSON works.
Todos
Get all todos
Show outputfetch('https://dummyjson.com/todos') .then(res => res.json()) .then(console.log);
Get a single todo
Show outputfetch('https://dummyjson.com/todos/1') .then(res => res.json()) .then(console.log);
Get a random todo
Show outputfetch('https://dummyjson.com/todos/random') .then(res => res.json()) .then(console.log);
Limit and skip todos
You can pass "limit" and "skip" params to limit and skip the results for pagination, and use limit=0 to get all items.
Show outputfetch('https://dummyjson.com/todos?limit=3&skip=10') .then(res => res.json()) .then(console.log);
Get all todos by user id
Show output/* getting todos of user with id 5 */ fetch('https://dummyjson.com/todos/user/5') .then(res => res.json()) .then(console.log);
Add a new todo
Adding a new todo will not add it into the server.
It will simulate a POST request and will return the new created
todo with a new id
Show outputfetch('https://dummyjson.com/todos/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ todo: 'Use DummyJSON in the project', completed: false, userId: 5, }) }) .then(res => res.json()) .then(console.log);
Update a todo
Updating a todo will not update it into the server.
It will simulate a PUT/PATCH request and will return the todo with
modified data
Show output/* updating completed status of todo with id 1 */ fetch('https://dummyjson.com/todos/1', { method: 'PUT', /* or PATCH */ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ completed: false, }) }) .then(res => res.json()) .then(console.log);
Delete a todo
Deleting a todo will not delete it into the server.
It will simulate a DELETE request and will return deleted todo
with "isDeleted" & "deletedOn" keys
Show outputfetch('https://dummyjson.com/todos/1', { method: 'DELETE', }) .then(res => res.json()) .then(console.log);