You can perform CRUD operations on products using the /products endpoint. Note that changes are not permanent.
// Get all products
fetch("https://fakestoreapi.com/products")
.then((res) => res.json())
.then((json) => console.log(json));
// Get a single product
fetch("https://fakestoreapi.com/products/1")
.then((res) => res.json())
.then((json) => console.log(json));
// Add new product (returns fake ID)
fetch("https://fakestoreapi.com/products", {
method: "POST",
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "https://i.pravatar.cc",
category: "electronic",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
// Update a product (PUT)
fetch("https://fakestoreapi.com/products/7", {
method: "PUT",
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "https://i.pravatar.cc",
category: "electronic",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
// Partial update a product (PATCH)
fetch("https://fakestoreapi.com/products/8", {
method: "PATCH",
body: JSON.stringify({
title: "test product",
price: 13.5,
description: "lorem ipsum set",
image: "https://i.pravatar.cc",
category: "electronic",
}),
})
.then((res) => res.json())
.then((json) => console.log(json));
// Delete a product
fetch("https://fakestoreapi.com/products/8", {
method: "DELETE",
});