What is this API?
This is a complete, production-ready REST API that you can use for free to build your e-commerce applications. Whether you're building a web application, mobile app, or integrating e-commerce functionality into an existing system, this API provides all the endpoints you need.
The API is built using modern technologies and follows best practices, ensuring reliability, scalability, and security. It includes authentication, authorization, data validation, and comprehensive error handling.
✨ Key Features
🔐 Authentication & Authorization
Secure JWT-based authentication with role-based access control (User and Admin roles).
📦 Product Management
Complete CRUD operations for products with categories, subcategories, stock management, search, pagination, and sorting.
🔍 Advanced Search
Search products by name or ID with case-insensitive partial matching for quick product discovery.
📄 Pagination & Sorting
Optional pagination with metadata and flexible sorting by price, name, stock, or dates for efficient data handling.
🛒 Order Management
Full order lifecycle management from creation to delivery tracking.
📂 Category System
Organized category and subcategory structure with AI-generated images for better product organization and visual appeal.
✅ Input Validation
Comprehensive request validation to ensure data integrity and security.
🖼️ Image Support
Categories and subcategories include AI-generated images from Unsplash for rich visual content.
📖 API Documentation
Interactive Swagger UI documentation for easy testing and integration.
🔒 Security
Password hashing with bcrypt, JWT tokens, and secure error handling.
⚡ Fast & Scalable
Built with Express and MongoDB for high performance and scalability.
🗄️ Database Management
Easy database seeding and reset scripts with comprehensive sample data (15 categories, 75 subcategories, 131+ products).
🔗 API Endpoints
Complete RESTful API with endpoints for all operations:
🔐 Authentication
- POST
/api/auth/register- Register a new user - POST
/api/auth/login- Login user
📁 Categories
- GET
/api/categories- Get all categories (with images) - GET
/api/categories/:id- Get category by ID (with image) - POST
/api/categories- Create category (Admin) - PUT
/api/categories/:id- Update category (Admin) - DELETE
/api/categories/:id- Delete category (Admin)
📂 SubCategories
- GET
/api/subcategories- Get all subcategories (with images) - GET
/api/subcategories/:id- Get subcategory by ID (with image) - POST
/api/subcategories- Create subcategory (Admin) - PUT
/api/subcategories/:id- Update subcategory (Admin) - DELETE
/api/subcategories/:id- Delete subcategory (Admin)
🛍️ Products
- GET
/api/products- Get all products - GET
/api/products?search- Search by name/ID - GET
/api/products?category- Filter by category - GET
/api/products?page&limit- Pagination - GET
/api/products?sortBy&sortOrder- Sorting - GET
/api/products/:id- Get product by ID - POST
/api/products- Create product (Admin) - PUT
/api/products/:id- Update product (Admin) - DELETE
/api/products/:id- Delete product (Admin)
📋 Orders
- POST
/api/orders- Submit an order - GET
/api/orders- Get user's orders - GET
/api/orders/:id- Get order details
🚀 Getting Started
Follow these simple steps to start using the API:
-
Get Your API Base URL
Use our hosted API:
https://freefakeapi.com -
Register a User Account
Create an account to get your authentication token:
POST /api/auth/register { "name": "John Doe", "email": "[email protected]", "password": "password123" }
-
Login to Get Your Token
Login with your credentials to receive a JWT token:
POST /api/auth/login { "email": "[email protected]", "password": "password123" } // Response includes a token - save this for authenticated requests
-
Make Authenticated Requests
Include your token in the Authorization header for protected endpoints:
Headers: Authorization: Bearer YOUR_JWT_TOKEN_HERE GET /api/products
-
Explore the API
Use the interactive Swagger documentation to test endpoints and see examples:
💻 Usage Examples
Here are some common use cases:
Fetch All Products
fetch('http://localhost:3000/api/products') .then(res => res.json()) .then(data => console.log(data));
Search Products with Pagination
fetch('http://localhost:3000/api/products?search=iPhone&page=1&limit=10&sortBy=price&sortOrder=asc') .then(res => res.json()) .then(data => { // data.data contains products // data.pagination contains pagination info console.log(data); });
Submit an Order
fetch('http://localhost:3000/api/orders', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_TOKEN' }, body: JSON.stringify({ items: [ { product: 'productId', quantity: 2 } ], shippingAddress: { street: '123 Main St', city: 'New York', state: 'NY', zipCode: '10001', country: 'USA' } }) })
🛠️ Built With
Node.js
JavaScript runtime for server-side development
Express
Fast, minimalist web framework
TypeScript
Type-safe JavaScript for better development
MongoDB
NoSQL database for flexible data storage
JWT
Secure token-based authentication
Mongoose
MongoDB object modeling library