How we use it.

fakeStoreApi can be used with any type of shopping project that needs products, carts, and users in JSON format. you can use examples below to check how fakeStoreApi works and feel free to enjoy it in your awesome projects!

Get your API key simply, by justSignUp

Products

Users having API key can add, update, delete a product in the Database using their API key.
You can pass in the API Key to our APIs either by using the Authorization (Bearer Token) header or by sending an apiKey parameter via the query string or request body.
If you don't provide API Key, then you will get default products only. With API key can get both your added products and default products.

Get all products

fetch("https://fakestores.onrender.com/api/products", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Get a single product

fetch("https://fakestores.onrender.com/api/products/5LyQpt", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Limit results

fetch("https://fakestores.onrender.com/api/products?limit=5", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Sort results

Default value is in ascending mode, you can use with 'desc' or 'asc' as you want. Sorting is based on 'id'.
fetch("https://fakestores.onrender.com/api/products?sort='desc", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Get all categories

fetch("https://fakestores.onrender.com/api/categories", {
method: "GET",
}).then(res=> res.json())
  .then(result=> console.log(result))

Get products in a specific category

You can also use limit(Number) and sort(asc|desc) as a query string to get your ideal results.
fetch("https://fakestores.onrender.com/api/products/category/electronics", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Add new product

Title, Price, Category these fileds are required in request body! If you do not mention an Id in request body, then 6char Id will be created automatically. You can set availability as 'OutOfStock', by default is 'InStock'
If you try to add new product without valid apiKey, then response will be "You don't have permission! Please Provide apiKey".
fetch("https://fakestores.onrender.com/api/product/add/", {
method: "POST",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "title": "test product",
  "price": 1000,
  "description": "This is a test product.",
  "category": "electronics",
  "imageURL": "https://via.placeholder.com/350/6366f1",
  "rating": 4.2,
  "availability": "InStock",
  "seller": "FakeStore",
  "source": "https://www.flipkart.com/"
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

Update a product by Id

User can update only his/her added product.
It will return you a response with updated product details. If you try to update a product without valid apiKey, then response will be "You don't have permission! Please Provide apiKey".
fetch("https://fakestores.onrender.com/api/products/update/5LyQpt", {
method: "PATCH",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "title": "Updated test product",
  "price": 999,
  "description": "This is updated test product.",
  "rating": 4.5,
  "availability": "OutOfStock"
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

Delete a product by Id

User can delete only his/her added products.
If you try to update a product without valid apiKey, then response will be "You don't have permission! Please Provide apiKey"
fetch("https://fakestores.onrender.com/api/products/delete/5LyQpt", {
method: "DELETE",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Cart

Users can add, remove products from their cart, using their API Key.
You can pass in the API Key to our APIs either by using the Authorization (Bearer Token) header or by sending an apiKey parameter via the query string or request body.
But, note that these cartProducts will get automatically empty from databse after 48hours of adding product into cart!
Test userId = pso3d5
Test apiKey of this user = d8cadd2d-0ee2-4bc3-8da0-8eef4afb8288
Without API key you will get response of only default user's cart. If you wants to get your cart along with default carts then you must have to send apiKey

Get all Carts

fetch("https://fakestores.onrender.com/api/carts", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Get a single Cart

fetch("https://fakestores.onrender.com/api/carts/test-684", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Add product to cart

You can add products to your cart only, using your API key.
fetch("https://fakestores.onrender.com/api/cart/product/add/test-684", {
method: "PATCH",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "productId": "RMoJhx",
  "quantity": 2
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

Remove product from cart

You can remove products from your cart only, using your API key.
fetch("https://fakestores.onrender.com/api/cart/product/remove/test-864", {
method: "PATCH",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "productId": "RMoJhx",
  "quantity": 1
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

Users

User Sign Up

Nothing in real will insert into the database. It will return dummy response
fetch("https://fakestores.onrender.com/api/signup", {
method: "POST",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "email": "test@test.com",
  "password": "test"
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

User Log In

It will not check for valid user into the database. It will return dummy login response with given credentials
fetch("https://fakestores.onrender.com/api/login", {
method: "POST",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "email": "test@test.com",
  "password": "test"
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

User Logout

It will not check for valid user into the database. It will return dummy logout response with given credentials
fetch("https://fakestores.onrender.com/api/logout", {
method: "DELETE",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
body: JSON.stringify(
{
  "email": "test@test.com",
  "password": "test"
}
)
}).then(res=> res.json())
  .then(result=> console.log(result))

Get all Users.

Without API key you will get default users only.
fetch("https://fakestores.onrender.com/api/users/", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Get a single User.

To get your user details you have to send apiKey.
fetch("https://fakestores.onrender.com/api/users/test-684/", {
method: "GET",
headers: {
  "Accept": "application/json",
  "Content-Type": "application/json",
  },
}).then(res=> res.json())
  .then(result=> console.log(result))

Made with ☕ and 💻 by Parshuram Nikam