📚 Documentation

Guide complet de l'API

Apprenez à utiliser FakeStore API pour créer des applications d'e-commerce modernes. Des exemples pratiques et une référence complète pour tous les endpoints.

🛍️ 20+ Produits
🛒 Paniers complets
👥 10 Utilisateurs
🔐 Auth JWT

🚀 Comment utiliser l'API

FakeStore API peut être utilisée avec n'importe quel type de projet e-commerce nécessitant des produits, des paniers et des utilisateurs au format JSON. Utilisez les exemples ci-dessous pour découvrir comment fonctionne l'API et intégrez-la dans vos projets !

⚡ Démarrage rapide

GET http://localhost:3000/products
// Exemple avec fetch API moderne
const response = await fetch('http://localhost:3000/products');
const products = await response.json();
console.log(products);

Products

Get all products

fetch('https://grineasy.com/products')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            [
                {
                    id:1,
                    title:'...',
                    price:'...',
                    category:'...',
                    description:'...',
                    image:'...'
                },
                /*...*/
                {
                    id:30,
                    title:'...',
                    price:'...',
                    category:'...',
                    description:'...',
                    image:'...'
                }
            ]
        

Get a single product

fetch('https://grineasy.com/products/1')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            {
                id:1,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
        

Limit results

fetch('https://grineasy.com/products?limit=5')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
        [
            {
                id:1,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
            /*...*/
            {
                id:5,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
        ]
        

Sort results

fetch('https://grineasy.com/products?sort=desc')
            .then(res=>res.json())
            .then(json=>console.log(json))

Default value is in ascending mode, you can use with 'desc' or 'asc' as you want.


            //output
        [
            {
                id:30,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
            /*...*/
            {
                id:1,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
        ]
        

Get all categories

fetch('https://grineasy.com/products/categories')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            [
            "electronics",
            "jewelery",
            "men's clothing",
            "women's clothing"
            ]
        

Get products in a specific category

fetch('https://grineasy.com/products/category/jewelery')
            .then(res=>res.json())
            .then(json=>console.log(json))

You can also use limit(Number) and sort(asc|desc) as a query string to get your ideal results


            //output
        [
            {
                id:5,
                title:'...',
                price:'...',
                category:'jewelery',
                description:'...',
                image:'...'
            }
            /*...*/
            {
                id:8,
                title:'...',
                price:'...',
                category:'jewelery',
                description:'...',
                image:'...'
            }
        ]
        

Add new product

fetch('https://grineasy.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))

If you send an object like the code above, it will return you an object with a new id. remember that nothing in real will insert into the database. so if you want to access the new id you will get a 404 error.


            //output
            {
                id:31,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
        

Update a product

fetch('https://grineasy.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))
fetch('https://grineasy.com/products/7',{
                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))

It will return you an object with sent id. remember that nothing in real will update in the database.


            //output
            {
                id:7,
                title:'new title',
                price:'new price',
                category:'new category',
                description:'new description',
                image:'new image url'
            }
        

Delete a product

fetch('https://grineasy.com/products/6',{
            method:"DELETE"
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

The product will not be deleted on the database. but if you sent data successfully it will return you the fake deleted product.


            //output
            {
                id:6,
                title:'...',
                price:'...',
                category:'...',
                description:'...',
                image:'...'
            }
        

Cart

Get all carts

fetch('https://grineasy.com/carts')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            [
                {
                    id:1,
                    userId:1,
                    date:2020-10-10,
                    products:[{productId:2,quantity:4},{productId:1,quantity:10},{productId:5,quantity:2}]
                },
                /*...*/
                {
                    id:20,
                    userId:10,
                    date:2019-10-10,
                    products:[{productId:1,quantity:5},{productId:5,quantity:1}]
                }
            ]
        

Get a single cart

fetch('https://grineasy.com/carts/5')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            {
                id:5,
                userId:1,
                date:...,
                products:[...]
            }
        

Limit results

fetch('https://grineasy.com/carts?limit=5')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
        [
            {
                id:1,
                userId:1,
                date:...,
                products:[...]
            },
            /*...*/
            {
                id:5,
                userId:1,
                date:...,
                products:[...]
            }
        ]
        

Sort results

fetch('https://grineasy.com/carts?sort=desc')
            .then(res=>res.json())
            .then(json=>console.log(json))

The default value is in ascending mode, you can use it with 'desc' or 'asc' as you want.


            //output
        [
            {
                id:20,
                userId:1,
                date:...,
                products:[...]
            },
            /*...*/
            {
                id:1,
                userId:1,
                date:...,
                products:[...]
            }
        ]
        

Get carts in a date range

fetch('https://grineasy.com/carts/startdate=2019-12-10&enddate=2020-10-10')
            .then(res=>res.json())
            .then(json=>console.log(json))

If you don't add any start date it will fetch from the beginning of time and if you don't add any end date it will fetch until now. You can also use limit(Number) and sort(asc|desc) as a query string to get your ideal results


            //output
    [
        {
            id:1,
            userId:1,
            date:2019-12-10,
            products:[...]
        },
        /*...*/
        {
            id:4,
            userId:1,
            date:2020-10-10,
            products:[...]
        }
    ]
        

Get user carts

fetch('https://grineasy.com/carts/user/2')
            .then(res=>res.json())
            .then(json=>console.log(json))

You can also use date range as query string to get your ideal results


            //output
            [
            {
                id:5,
                userId:2,
                date:2019-10-03,
                products:[...]
            },
            /*...*/
            {
                id:6,
                userId:2,
                date:2020-10-10,
                products:[...]
            }
        ]
        

Add a new product

fetch('https://grineasy.com/carts',{
            method:"POST",
            body:JSON.stringify(
                {
                    userId:5,
                    date:2020-02-03,
                    products:[{productId:5,quantity:1},{productId:1,quantity:5}]
                }
            )
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

If you send an object like the code above, it will return you an object with a new id. remember that nothing in real will insert into the database. so if you want to access the new id you will get a 404 error.


            //output
            {
                id:21
                userId:5,
                date:2020-02-03,
                products:[{productId:5,quantity:1},{productId:1,quantity:5}]
            }
        

Update a product

fetch('https://grineasy.com/carts/7',{
            method:"PUT",
            body:JSON.stringify(
                {
                    userId:3,
                    date:2019-12-10,
                    products:[{productId:1,quantity:3}]
                }
            )
        })
            .then(res=>res.json())
            .then(json=>console.log(json))
fetch('https://grineasy.com/carts/7',{
                method:"PATCH",
                body:JSON.stringify(
                    {
                        userId:3,
                        date:2019-12-10,
                        products:[{productId:1,quantity:3}]
                    }
                )
            })
                .then(res=>res.json())
                .then(json=>console.log(json))

It will return you an object with sent id. remember that nothing in real will update in the database.


            //output
            {
                id:7,
                userId:3,
                date:2019-12-10,
                products:[{productId:1,quantity:3}]
            }
        

Delete a cart

fetch('https://grineasy.com/carts/6',{
            method:"DELETE"
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

The cart will not be deleted on the database. but if you sent data successfully it will return you the fake deleted cart.


            //output
            {
                id:6,
                userId:...,
                date:...,
                products:[...]
            }
        

Users

Get all users

fetch('https://grineasy.com/users')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
    [
        {
            id:1,
            email:'John@gmail.com',
            username:'johnd',
            password:'m38rmF$',
            name:{
                firstname:'John',
                lastname:'Doe'
            },
            address:{
                city:'kilcoole',
                street:'7835 new road',
                number:3,
                zipcode:'12926-3874',
                geolocation:{
                    lat:'-37.3159',
                    long:'81.1496'
                }
            },
            phone:'1-570-236-7033'
        },
        /*...*/
        {
            id:20,
            email:'...',
            username:'...',
            password:'...',
            name:{
                firstname:'...',
                lastname:'...'
            },
            address:{
                city:'...',
                street:'...',
                number:...,
                zipcode:'...',
                geolocation:{
                    lat:'...',
                    long:'...'
                }
            },
            phone:'...'
        }
    ]
        

Get a single user

fetch('https://grineasy.com/users/1')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            {
                id:1,
                email:'John@gmail.com',
                username:'johnd',
                password:'m38rmF$',
                name:{
                    firstname:'John',
                    lastname:'Doe'
                },
                address:{
                    city:'kilcoole',
                    street:'7835 new road',
                    number:3,
                    zipcode:'12926-3874',
                    geolocation:{
                        lat:'-37.3159',
                        long:'81.1496'
                    }
                },
                phone:'1-570-236-7033'
            }
        

Limit results

fetch('https://grineasy.com/users?limit=5')
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
            [
            {
                id:1,
                email:'John@gmail.com',
                username:'johnd',
                password:'m38rmF$',
                name:{
                    firstname:'John',
                    lastname:'Doe'
                },
                address:{
                    city:'kilcoole',
                    street:'7835 new road',
                    number:3,
                    zipcode:'12926-3874',
                    geolocation:{
                        lat:'-37.3159',
                        long:'81.1496'
                    }
                },
                phone:'1-570-236-7033'
            },
            /*...*/
            {
                id:5,
                email:'...',
                username:'...',
                password:'...',
                name:{
                    firstname:'...',
                    lastname:'...'
                },
                address:{
                    city:'...',
                    street:'...',
                    number:...,
                    zipcode:'...',
                    geolocation:{
                        lat:'...',
                        long:'...'
                    }
                },
                phone:'...'
            }
        ]
        

Sort results

fetch('https://grineasy.com/users?sort=desc')
            .then(res=>res.json())
            .then(json=>console.log(json))

The default value is in ascending mode, you can use it with 'desc' or 'asc' as you want.


            //output
        [
            {
                id:20,
                email:'...',
                username:'...',
                password:'...',
                name:{
                    firstname:'...',
                    lastname:'...'
                },
                address:{
                    city:'...',
                    street:'...',
                    number:...,
                    zipcode:'...',
                    geolocation:{
                        lat:'...',
                        long:'...'
                    }
                },
                phone:'...'
            },
            /*...*/
            {
                id:1,
                email:'...',
                username:'...',
                password:'...',
                name:{
                    firstname:'...',
                    lastname:'...'
                },
                address:{
                    city:'...',
                    street:'...',
                    number:...,
                    zipcode:'...',
                    geolocation:{
                        lat:'...',
                        long:'...'
                    }
                },
                phone:'...'
            }
        ]
        

Add a new user

fetch('https://grineasy.com/users',{
            method:"POST",
            body:JSON.stringify(
                {
                    email:'John@gmail.com',
                    username:'johnd',
                    password:'m38rmF$',
                    name:{
                        firstname:'John',
                        lastname:'Doe'
                    },
                    address:{
                        city:'kilcoole',
                        street:'7835 new road',
                        number:3,
                        zipcode:'12926-3874',
                        geolocation:{
                            lat:'-37.3159',
                            long:'81.1496'
                        }
                    },
                    phone:'1-570-236-7033'
                }
            )
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

If you send an object like the code above, it will return you an object with a new id. remember that nothing in real will insert into the database. so if you want to access the new id you will get a 404 error.


            //output
            {
                id:21,
                email:'John@gmail.com',
                username:'johnd',
                password:'m38rmF$',
                name:{
                    firstname:'John',
                    lastname:'Doe'
                },
                address:{
                    city:'kilcoole',
                    street:'7835 new road',
                    number:3,
                    zipcode:'12926-3874',
                    geolocation:{
                        lat:'-37.3159',
                        long:'81.1496'
                    }
                },
                phone:'1-570-236-7033'
            }
        

Update a users

fetch('https://grineasy.com/users/7',{
            method:"PUT",
            body:JSON.stringify(
                {
                email:'John@gmail.com',
                username:'johnd',
                password:'m38rmF$',
                name:{
                    firstname:'John',
                    lastname:'Doe'
                },
                address:{
                    city:'kilcoole',
                    street:'7835 new road',
                    number:3,
                    zipcode:'12926-3874',
                    geolocation:{
                        lat:'-37.3159',
                        long:'81.1496'
                    }
                },
                phone:'1-570-236-7033'
                }
            )
        })
            .then(res=>res.json())
            .then(json=>console.log(json))
fetch('https://grineasy.com/users/7',{
                method:"PATCH",
                body:JSON.stringify(
                    {
                        email:'John@gmail.com',
                        username:'johnd',
                        password:'m38rmF$',
                        name:{
                            firstname:'John',
                            lastname:'Doe'
                        },
                        address:{
                            city:'kilcoole',
                            street:'7835 new road',
                            number:3,
                            zipcode:'12926-3874',
                            geolocation:{
                                lat:'-37.3159',
                                long:'81.1496'
                            }
                        },
                        phone:'1-570-236-7033'
                    }
                )
            })
                .then(res=>res.json())
                .then(json=>console.log(json))

It will return you an object with sent id. remember that nothing in real will update in the database.


            //output
            {
                id:7,
                email:'John@gmail.com',
                username:'johnd',
                password:'m38rmF$',
                name:{
                    firstname:'John',
                    lastname:'Doe'
                },
                address:{
                    city:'kilcoole',
                    street:'7835 new road',
                    number:3,
                    zipcode:'12926-3874',
                    geolocation:{
                        lat:'-37.3159',
                        long:'81.1496'
                    }
                },
                phone:'1-570-236-7033'
            }
        

Delete a user

fetch('https://grineasy.com/users/6',{
            method:"DELETE"
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

The user will not be deleted on the database. but if you sent data successfully it will return you the fake deleted user.


            //output
            {
                id:6,
                email:'John@gmail.com',
                username:'johnd',
                password:'m38rmF$',
                name:{
                    firstname:'John',
                    lastname:'Doe'
                },
                address:{
                    city:'kilcoole',
                    street:'7835 new road',
                    number:3,
                    zipcode:'12926-3874',
                    geolocation:{
                        lat:'-37.3159',
                        long:'81.1496'
                    }
                },
                phone:'1-570-236-7033'
            }
        

Login

User login

fetch('https://grineasy.com/auth/login',{
            method:'POST',
            body:JSON.stringify({
                username: "mor_2314",
                password: "83r5^_"
            })
        })
            .then(res=>res.json())
            .then(json=>console.log(json))

            //output
        {
            token: "eyJhbGciOiJIUzI1NiIsInR"
        }
        

You can use any of the users' username and password available in users API to get token. any other usernames return error.