Docs
You can use examples below to check how DummyJSON works.
Todos
Get all todos
fetch('https://dj.tdn.wf/todos')
.then(res => res.json())
.then(console.log);
Show output
Get a single todo
fetch('https://dj.tdn.wf/todos/1')
.then(res => res.json())
.then(console.log);
Show output
Get a random todo
fetch('https://dj.tdn.wf/todos/random')
.then(res => res.json())
.then(console.log);
Show output
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.
fetch('https://dj.tdn.wf/todos?limit=3&skip=10')
.then(res => res.json())
.then(console.log);
Show output
Get all todos by user id
/* getting todos of user with id 5 */
fetch('https://dj.tdn.wf/todos/user/5')
.then(res => res.json())
.then(console.log);
Show output
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
fetch('https://dj.tdn.wf/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);
Show output
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
/* updating completed status of todo with id 1 */
fetch('https://dj.tdn.wf/todos/1', {
method: 'PUT', /* or PATCH */
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
completed: false,
})
})
.then(res => res.json())
.then(console.log);
Show output
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
fetch('https://dj.tdn.wf/todos/1', {
method: 'DELETE',
})
.then(res => res.json())
.then(console.log);
Show output