FREE JSON API

Simple Fake API

Use our JSON files as a simple fake API for your frontend projects, testing, learning and development.

https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/

What is this API?

This project provides simple JSON files that can be used as a fake API. You can fetch categories and products directly from your JavaScript application using the native Fetch API.

Categories

Get all available product categories from category.json.

/category.json
Products

Get products from your products.json file.

/products.json
Easy Integration

Integrate the API in any frontend using JavaScript fetch().

fetch()

API Endpoints

Available JSON resources

Categories

GET LIVE

Returns a list of available categories.

https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/category.json
Example Response
 
[
  {
    "id": 1,
    "name": "Men",
    "description": "Modern essentials",
    "image": "https://images.unsplash.com"
  },
  {
    "id": 2,
    "name": "Women",
    "description": "Effortless elegance",
    "image": "https://images.unsplash.com"
  }
]

Products

GET LIVE

Returns a list of available products.

https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/products.json
Example Response

[
  {
    "id": 1,
    "name": "Classic Oversized Shirt",
    "category": "Men",
    "price": 59,
    "oldPrice": 79,
    "badge": "Best Seller",
    "image": "https://images.unsplash.com/"
  },
   {
    "id": 2,
    "name": "Minimal Everyday Dress",
    "category": "Women",
    "price": 89,
    "oldPrice": 119,
    "badge": "Best Seller",
    "image": "https://images.unsplash.com/"
  }
]

Register

GET LIVE

Returns a registration user.

https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/register.json
Example Response
 
{
    "success": true,
    "message": "Registration successful",
    "user": {
        "id": 101,
        "name": "Muhammad Farhan",
        "email": "muhammadfarhan.developer@gmail.com",
        "username": "muhammadfarhan",
        "role": "customer"
    }
}

Login

GET LIVE

Returns a login user with Token.

https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/login.json
Example Response

{
    "success": true,
    "message": "Login successful",
    "user": {
        "id": 101,
        "name": "Muhammad Farhan",
        "email": "muhammadfarhan.developer@gmail.com",
        "username": "muhammadfarhan",
        "role": "customer"
    },
    "token": "fake_register_token_abcdef1234567890",
    "token_type": "Bearer"
}

JavaScript Integration

You can consume these JSON files using JavaScript fetch().

1. Fetch Categories
fetch('https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/category.json')
    .then(response => response.json())
    .then(categories => {
        console.log(categories);
    })
    .catch(error => {
        console.error('Error:', error);
    });
2. Fetch Products
fetch('https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/products.json')
    .then(response => response.json())
    .then(products => {
        console.log(products);
    })
    .catch(error => {
        console.error('Error:', error);
    });
3. Using Async / Await
async function getProducts() {

    try {

        const response = await fetch(
            'https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/products.json'
        );

        const products = await response.json();

        console.log(products);

    } catch (error) {

        console.error('Error:', error);

    }

}

getProducts();
4. User Registration
fetch('https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/register.json')
    .then(response => response.json())
    .then(data => {
        console.log(data);
        console.log(data.message);
    })
    .catch(error => {
        console.error('Error:', error);
    });
5. User Login
fetch('https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/login.json')
    .then(response => response.json())
    .then(data => {
        console.log(data);
        console.log(data.message);
        console.log(data.token); // bearer Fake token 
    })
    .catch(error => {
        console.error('Error:', error);
    });

Complete Example

Fetch products and display them on your website.

<div id="products"></div>

<script>

async function loadProducts() {

    const container = document.getElementById('products');

    try {

        const response = await fetch(
            'https://muhammadfarhandeveloper.github.io/E-Commerce-fakeapi/products.json'
        );

        const products = await response.json();

        products.forEach(product => {

            container.innerHTML += `
                <div class="card mb-3">
                    <div class="card-body">
                        <h5>${product.name}</h5>
                        <p>Price: $${product.price}</p>
                        <p>Category: ${product.category}</p>
                    </div>
                </div>
            `;

        });

    } catch (error) {

        container.innerHTML =
            '<p>Unable to load products.</p>';

        console.error(error);

    }

}

loadProducts();

</script>

How to Use

  1. Copy the public URL of your JSON files.
  2. Use the URL inside JavaScript fetch().
  3. Convert the response using response.json().
  4. Use the returned data anywhere in your frontend application.
Important

This is a static JSON API. It is ideal for frontend development, prototypes, testing, demos and learning. It does not provide database operations such as POST, PUT, PATCH or DELETE unless you add a backend/server that supports those operations.