Docs
You can use examples below to check how DummyJSON works.
Carts
Get all carts
Show outputfetch('https://dummyjson.com/carts') .then(res => res.json()) .then(console.log);
Get a single cart
Show outputfetch('https://dummyjson.com/carts/1') .then(res => res.json()) .then(console.log);
Get carts of a user
Show output// getting carts of user with id 5 fetch('https://dummyjson.com/carts/user/5') .then(res => res.json()) .then(console.log);
Add a new cart
Adding a new cart will not add it into the server.
It will simulate a POST request and will return the new created
cart with a new id
You can provide a userId and array of products as objects,
containing productId & quantity
Show outputfetch('https://dummyjson.com/carts/add', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: 1, products: [ { id: 1, quantity: 1, }, { id: 50, quantity: 2, }, ] }) }) .then(res => res.json()) .then(console.log);
Update a cart
Updating a cart will not update it into the server.
Pass "merge: true" to include old products when updating
It will simulate a PUT/PATCH request and will return updated cart
with modified data
You can provide a userId and array of products as objects,
containing productId & quantity
Show output/* adding products in cart with id 1 */ fetch('https://dummyjson.com/carts/1', { method: 'PUT', /* or PATCH */ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ merge: true, // this will include existing products in the cart products: [ { id: 1, quantity: 1, }, ] }) }) .then(res => res.json()) .then(console.log);
Delete a cart
Deleting a cart will not delete it into the server.
It will simulate a DELETE request and will return deleted cart
with "isDeleted" & "deletedOn" keys
Show outputfetch('https://dummyjson.com/carts/1', { method: 'DELETE', }) .then(res => res.json()) .then(console.log);