FakeStoreAPI is a free online REST API that you can use whenever you need Pseudo-real data for your e-commerce or shopping website without running any server-side code. It's awesome for teaching purposes, sample codes, tests and etc.
You can visit in detail docs in FakeStoreAPI for more information.
When I wanted to design a shopping website prototype and needed fake data, I had to use lorem ipsum data or create a JSON file from the base. I didn't find any online free web service to return semi-real shop data instead of lorem ipsum data. so I decided to create this simple web service with NodeJs(express) and MongoDB as a database.
There are 4 main resources need in shopping prototypes:
you can fetch data with any kind of methods you know(fetch API, Axios, jquery ajax,...)
fetch("https://fakestoreapi.com/products")
.then((res) => res.json())
.then((json) => console.log(json));
fetch("https://fakestoreapi.com/products/1")
.then((res) => res.json())
.then((json) => console.log(json));
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));
/* will return
{
id:31,
title:'...',
price:'...',
category:'...',
description:'...',
image:'...'
}
*/
Note: Posted data will not really insert into the database and just return a fake id.
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));
/* will return
{
id:7,
title: 'test product',
price: 13.5,
description: 'lorem ipsum set',
image: 'https://i.pravatar.cc',
category: 'electronic'
}
*/
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));
/* will return
{
id:8,
title: 'test product',
price: 13.5,
description: 'lorem ipsum set',
image: 'https://i.pravatar.cc',
category: 'electronic'
}
*/
Note: Edited data will not really be updated into the database.
fetch("https://fakestoreapi.com/products/8", {
method: "DELETE",
});
Nothing will delete on the database.
You can use query string to limit results or sort by asc|desc
// Will return all the posts that belong to the first user
fetch("https://fakestoreapi.com/products?limit=3&sort=desc")
.then((res) => res.json())
.then((json) => console.log(json));
fields:
{
id:Number,
title:String,
price:Number,
category:String,
description:String,
image:String
}
GET:
POST:
-PUT,PATCH
-DELETE
fields:
{
id:Number,
userId:Number,
date:Date,
products:[{productId:Number,quantity:Number}]
}
GET:
POST:
PUT,PATCH:
DELETE:
fields:
{
id:20,
email:String,
username:String,
password:String,
name:{
firstname:String,
lastname:String
},
address:{
city:String,
street:String,
number:Number,
zipcode:String,
geolocation:{
lat:String,
long:String
}
},
phone:String
}
GET:
POST:
PUT,PATCH:
DELETE:
fields:
{
username:String,
password:String
}
POST: