Docs
You can use examples below to check how DummyJSON works.
Users
Get all users
fetch('https://dj.tdn.wf/users')
.then(res => res.json())
.then(console.log);
Show output
Get current auth user
/* providing token in bearer */
fetch('https://dj.tdn.wf/user/me', {
method: 'GET',
headers: {
'Authorization': 'Bearer /* YOUR_TOKEN_HERE */',
},
})
.then(res => res.json())
.then(console.log);
Show output
Get a single user
fetch('https://dj.tdn.wf/users/1')
.then(res => res.json())
.then(console.log);
Show output
Search users
fetch('https://dj.tdn.wf/users/search?q=John')
.then(res => res.json())
.then(console.log);
Show output
Filter users
You can pass key (nested keys with ".") and value as params to
filter users. (key and value are case-sensitive)
"limit", "skip" and "select" works too.
fetch('https://dj.tdn.wf/users/filter?key=hair.color&value=Brown')
.then(res => res.json())
.then(console.log);
Show output
Limit and skip users
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.
fetch('https://dj.tdn.wf/users?limit=5&skip=10&select=firstName,age')
.then(res => res.json())
.then(console.log);
Show output
Get user's carts by user id
/* getting carts of user with id 5 */
fetch('https://dj.tdn.wf/users/5/carts')
.then(res => res.json())
.then(console.log);
Show output
Get user's posts by user id
/* getting posts of user with id 5 */
fetch('https://dj.tdn.wf/users/5/posts')
.then(res => res.json())
.then(console.log);
Show output
Get user's todos by user id
/* getting todos of user with id 5 */
fetch('https://dj.tdn.wf/users/5/todos')
.then(res => res.json())
.then(console.log);
Show output
Add a new user
Adding a new user will not add it into the server.
It will simulate a POST request and will return the new created
user with a new id
fetch('https://dj.tdn.wf/users/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
firstName: 'Muhammad',
lastName: 'Ovi',
age: 250,
/* other user data */
})
})
.then(res => res.json())
.then(console.log);
Show output
Update a user
Updating a user will not update it into the server.
It will simulate a PUT/PATCH request and will return the user with
modified data
/* updating lastName of user with id 1 */
fetch('https://dj.tdn.wf/users/1', {
method: 'PUT', /* or PATCH */
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
lastName: 'Owais'
})
})
.then(res => res.json())
.then(console.log);
Show output
Delete a user
Deleting a user will not delete it into the server.
It will simulate a DELETE request and will return deleted user
with "isDeleted" & "deletedOn" keys
fetch('https://dj.tdn.wf/users/1', {
method: 'DELETE',
})
.then(res => res.json())
.then(console.log);
Show output