Docs
You can use examples below to check how DummyJSON works.
Products
Get all products
fetch('https://dummyjson.com/products')
.then(res => res.json())
.then(console.log);
Show output
Get a single product
fetch('https://dummyjson.com/products/1')
.then(res => res.json())
.then(console.log);
Show output
Search products
fetch('https://dummyjson.com/products/search?q=phone')
.then(res => res.json())
.then(console.log);
Show output
Limit and skip products
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://dummyjson.com/products?limit=10&skip=10&select=title,price')
.then(res => res.json())
.then(console.log);
Show output
Get all products categories
fetch('https://dummyjson.com/products/categories')
.then(res => res.json())
.then(console.log);
Show output
Get products of a category
fetch('https://dummyjson.com/products/category/smartphones')
.then(res => res.json())
.then(console.log);
Show output
Add a new product
Adding a new product will not add it into the server.
It will simulate a POST request and will return the new created
product with a new id
fetch('https://dummyjson.com/products/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: 'BMW Pencil',
/* other product data */
})
})
.then(res => res.json())
.then(console.log);
Show output
Update a product
Updating a product will not update it into the server.
It will simulate a PUT/PATCH request and will return the product
with modified data
/* updating title of product with id 1 */
fetch('https://dummyjson.com/products/1', {
method: 'PUT', /* or PATCH */
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title: 'iPhone Galaxy +1'
})
})
.then(res => res.json())
.then(console.log);
Show output
Delete a product
Deleting a product will not delete it into the server.
It will simulate a DELETE request and will return deleted product
with "isDeleted" & "deletedOn" keys
fetch('https://dummyjson.com/products/1', {
method: 'DELETE',
})
.then(res => res.json())
.then(console.log);
Show output