GithubHelp home page GithubHelp logo

keikaavousi / fake-store-api Goto Github PK

View Code? Open in Web Editor NEW
2.0K 2.0K 399.0 62.9 MB

FakeStoreAPI is a free online REST API that provides you fake e-commerce JSON data

Home Page: https://fakestoreapi.com

License: MIT License

JavaScript 24.36% SCSS 22.88% EJS 52.43% Shell 0.19% Dockerfile 0.13%

fake-store-api's Introduction

FakeStoreAPI

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.

Why?

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.

Resources

There are 4 main resources need in shopping prototypes:

New! "Rating" (includes rate and count) has been added to each product object!

How to

you can fetch data with any kind of methods you know(fetch API, Axios, jquery ajax,...)

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

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.

Updating a product

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.

Deleting a product

fetch("https://fakestoreapi.com/products/8", {
  method: "DELETE",
});

Nothing will delete on the database.

Sort and Limit

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));

All available routes

Products

fields:
{
    id:Number,
    title:String,
    price:Number,
    category:String,
    description:String,
    image:String
}

GET:

  • /products (get all products)
  • /products/1 (get specific product based on id)
  • /products?limit=5 (limit return results )
  • /products?sort=desc (asc|desc get products in ascending or descending orders (default to asc))
  • /products/products/categories (get all categories)
  • /products/category/jewelery (get all products in specific category)
  • /products/category/jewelery?sort=desc (asc|desc get products in ascending or descending orders (default to asc))

POST:

  • /products

-PUT,PATCH

  • /products/1

-DELETE

  • /products/1

Carts

fields:
{
    id:Number,
    userId:Number,
    date:Date,
    products:[{productId:Number,quantity:Number}]
}

GET:

  • /carts (get all carts)
  • /carts/1 (get specific cart based on id)
  • /carts?startdate=2020-10-03&enddate=2020-12-12 (get carts in date range)
  • /carts/user/1 (get a user cart)
  • /carts/user/1?startdate=2020-10-03&enddate=2020-12-12 (get user carts in date range)
  • /carts?limit=5 (limit return results )
  • /carts?sort=desc (asc|desc get carts in ascending or descending orders (default to asc))

POST:

  • /carts

PUT,PATCH:

  • /carts/1

DELETE:

  • /carts/1

Users

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:

  • /users (get all users)
  • /users/1 (get specific user based on id)
  • /users?limit=5 (limit return results )
  • /users?sort=desc (asc|desc get users in ascending or descending orders (default to asc))

POST:

  • /users

PUT,PATCH:

  • /users/1

DELETE:

  • /users/1

Auth

fields:
{
    username:String,
    password:String
}

POST:

  • /auth/login

ToDo

  • Add graphql support
  • Add pagination
  • Add another language support

fake-store-api's People

Contributors

bardiesel avatar csralvall avatar freakingeek avatar jacob-ebey avatar keikaavousi avatar ld-web avatar marvinjgh avatar mkeikaavousi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fake-store-api's Issues

Real shop API compatibility

Nice library. A better use case would be if you had (or had the possibility to add) api compatibility to real e commerce store apis, like strapi or commerce-layer. Is there any hidden compatibility that is not mentioned in the docs or do you plan to add adapters?
The usecase should be self explanatory.

Cheers :)

Category Access URL | men's clothing - women's clothing

Can access men's clothing category products using https://fakestoreapi.com/products/category/men's%20clothing url however, this is bit weird. We need to use hard code to access this url but if url endpoint was mens-clothing then everyone could use package like slugify

What's your opinion about this?

Status Code for Login Error

Hello.
I think when username and password are incorrect is better that return the status code 401.
but API always returns status code 200!

Cross-Origin Request Blocked

Hi I was trying to fetch data from the fake-store API but I received this error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://fakestoreapi.com/products?limit=5. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing.

This is my code:

fetch("https://fakestoreapi.com/products?limit=5", { mode: "cors", "content-type": "application/json", accept: "application/json", }) .then((res) => res.json()) .then((json) => console.log(json));

Login Token should contain User Id

Like the title, some get request requires an user ID (user data, cart), but when I decode the token I only see the username and iat, which aren't helpful because get user data and user cart by name aren't supported.

Here is what the payload looks like when I decoded it online. It should return an user ID instead of just username.

Screen Shot 2022-08-01 at 10 43 30

Licensing

Hi, thanks for building this great project!

Could you please specify a license? Without a license, it is unclear how we are allowed to use this code. Is it open-source?

Cannot login

Hi, it's nice to use your api service for mocking my app.
But i can't login.
Heres some screenshots:

image
Screenshot 2021-10-24 004511
Screenshot 2021-10-24 004540

Anyway how can i contribute to this project, about the mongo database, should i manually create my local database or what?

Thank you!

Site is down

The Site is showing connection timed out.
“visit cloudfare.com for more info”

Fake Store API is down

Hi, https://fakestoreapi.com/ is giving a 502 error. I am a student at a frontend bootcamp, we need to demo our e-commerce projects in 12 hours but the api is not working. Could you please take a look at it? Thanks in advance!

About the store mock data

Hi, i am a developer whose target language is not English and I also want to generate store mock data.

So i am curious about how the data is generated for this repository and i hope to get an answer.

Add more products and categories

  • We can add more products to each categories and also create new categories
  • Also add pagination feature for different categories.

SSL handshake failed

Hi, thanks for the project it helps me to build my project. but apparently there's something wrong when I try to hit the API, here's im attach the image.
can you help me explain what's wrong?
Screenshot 2021-04-19 194457

CORS Error

Access to fetch at 'https://fakestoreapi.com/products/1' from origin 'https://fakestoreapi.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Product image backgrounds

It would be desirable to get the product images without the white background as it is obtrusive when trying to use the images on any background different from white.

FakeStoreApi down?

hi Guys

I was trying to fetch some data using axios for a list of products but i keep getting the same ssues 'Unexpected token < in JSON at position 0' , is is possible to fix this ?

kind regards ,

Joël Karhamaba
Schermafbeelding 2021-09-12 om 21 23 47
Schermafbeelding 2021-09-12 om 21 21 43

FakeStore API is down

Hello! I noticed that today the API is giving a status code 502. Yesterday it was working just fine. Thank you and have a nice day!

payment request

Hello, how are you
Thank you for developing this project. I am currently building a training application for me, and your project is really useful to me
I'm just wondering if you can soon build a payment api like a request that asks for data for example and I send it so that it is an integrated store project and everyone who uses your project I think needs something like that, so it will be useful for everyone

Problem with CORS

I'm trying to login user and always have this error:

Access to fetch at 'https://fakestoreapi.com/auth/login' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

API is very slow

I am using this API in one of my react project. I have deployed the app in heroku and when I try access the app. It takes almost 19seconds to fetch the products. I think the API is very slow.
WhatsApp Image 2022-03-08 at 9 09 02 PM

Updating user always returns 500 status code

Currently writing an app in kotlin and encountered a problem while writing the "update user" part, no matter what data I send along the request (as a body) it always returns 500 status code, tried using postman and even requests (python library) to test it, no result.
Example:
`
link = "https://fakestoreapi.com/users/7"

data = {
'email': '[email protected]',
'username': 'johnd',
'password': 'password',
'name': {'firstname': 'John', 'lastname': "Doe"},
'address': {'city': 'kilcoole', 'street': '7835 new road', 'number': '3',
'geolocation': {'lat': '-37.3159', 'long': '81.1496'}},
'phone': '1-570-236-7033'
}

request = requests.put(link, data=data)
print(request.status_code)
`

API is very slow

I am using this API in one of my react project. I have deployed the app in heroku and when I try access the app. It takes almost 19seconds to fetch the products. I think the API is very slow.
WhatsApp Image 2022-03-08 at 9 09 02 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.