fake-api-cli
Generate realistic fake REST APIs in seconds.
A lightweight, configurable REST API generator powered by Faker. Build mock APIs for frontend development, testing, prototyping, demos, and hackathons without writing a backend.
Features
- Generate complete REST APIs in seconds
- Zero database setup
- Built-in generators for common resources
- Custom schema-based resource generation
- Resource references (
@users.id) - Nested objects
- Arrays
- Automatic JSON persistence
- Filtering
- Pagination
- Sorting
- Search
- Field selection
- Full CRUD support
- Simple CLI
- Swagger UI
- Written entirely in TypeScript
Why fake-api?
Frontend developers often need an API before the backend is ready.
Instead of manually creating JSON files or spinning up a database, fake-api generates a realistic REST API with configurable resources, relationships, and fake data.
Perfect for:
- Frontend development
- UI prototyping
- Hackathons
- Portfolio projects
- Testing REST clients
- Learning API integration
Installation
Install globally
npm install -g fake-api-cli
Or use directly with NPX
npx fake-api-cli start
Quick Start
Create a configuration file.
export default {
port: 3000,
persistence: true,
database: "./fake-api-db.json",
resources: {
users: {
count: 100,
schema: {
name: "person.fullName",
email: "internet.email",
city: "location.city",
},
},
},
};
Start the server.
fake-api start
Output
✔ Fake API Server Started
URL:
http://localhost:3000
Resources:
• /users
Swagger:
/docs
Now open
http://localhost:3000/users
You'll instantly have a fully working REST API.
Example Response
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"city": "London"
},
{
"id": 2,
"name": "Alice Smith",
"email": "alice@example.com",
"city": "Paris"
}
]
Supported HTTP Methods
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all records |
| GET | /users/:id |
Get a single record |
| POST | /users |
Create a record |
| PUT | /users/:id |
Replace a record |
| PATCH | /users/:id |
Update part of a record |
| DELETE | /users/:id |
Delete a record |
Built-in Resources
Out of the box, fake-api includes generators for:
- Users
- Products
- Posts
Example
resources: {
users: {
count: 100,
},
products: {
count: 50,
},
posts: {
count: 25,
},
}
Need something else?
Just define a schema and fake-api generates it automatically.
Custom Schema Generation
Create completely custom resources without writing generators.
resources: {
books: {
count: 5,
schema: {
title: "book.title",
author: "person.fullName",
pages: "number.int(100,500)",
},
},
}
Output
{
"id": 1,
"title": "The Hobbit",
"author": "Jane Doe",
"pages": 341
}
Nested Objects
schema: {
name: "person.fullName",
address: {
city: "location.city",
country: "location.country",
},
}
Result
{
"name": "John",
"address": {
"city": "London",
"country": "United Kingdom"
}
}
Arrays
skills: [
"helpers.arrayElement(React,Node,Go)",
"helpers.arrayElement(TypeScript,Rust,Python)"
]
Produces
{
"skills": [
"React",
"TypeScript"
]
}
Resource References
Resources can reference records from other resources using the @resource.field syntax.
Example
resources: {
users: {
count: 100,
schema: {
name: "person.fullName",
},
},
posts: {
count: 200,
schema: {
title: "lorem.sentence",
userId: "@users.id",
},
},
}
Generated output
{
"id": 1,
"title": "My First Post",
"userId": 42
}
References are randomly selected from existing records.
They can also be used inside arrays.
friends: [
"@users.id",
"@users.id"
]
Result
{
"friends": [14, 87]
}
Query Parameters
Every generated resource automatically supports powerful query operations.
Pagination
GET /users?page=1&limit=10
Sorting
Ascending
GET /users?sort=name
Descending
GET /users?sort=-name
Multiple fields
GET /users?sort=city,-name
Filtering
Equality
GET /users?city=London
Not equal
GET /users?city_ne=London
Greater than
GET /products?price_gt=100
Greater than or equal
GET /products?price_gte=100
Less than
GET /products?price_lt=500
Less than or equal
GET /products?price_lte=500
IN operator
GET /users?role_in=Admin,Manager
Search
Search across supported fields.
GET /users?search=john
Field Selection
Return only selected fields.
GET /users?fields=id,name,email
Response
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
]
Persistence
When persistence is enabled, all changes are automatically written to a JSON database.
export default {
persistence: true,
database: "./fake-api-db.json",
}
Supported operations:
- POST
- PUT
- PATCH
- DELETE
Changes are immediately persisted to disk.
Swagger UI
Every server exposes interactive API documentation.
http://localhost:3000/docs
Swagger allows you to:
- Explore endpoints
- Execute requests
- View responses
- Test CRUD operations
No additional configuration required.
CLI
Start the server
fake-api start
Using NPX
npx fake-api-cli start
Development
npm run dev -- start
Build
npm run build
Configuration
A typical configuration file looks like this.
export default {
port: 3000,
delay: 0,
persistence: true,
database: "./fake-api-db.json",
auth: false,
resources: {
users: {
count: 100,
schema: {
name: "person.fullName",
email: "internet.email",
city: "location.city",
},
},
},
}
Project Structure
fake-api/
├── src/
│ ├── cli/
│ ├── config/
│ ├── controllers/
│ ├── database/
│ ├── generators/
│ ├── query/
│ ├── routes/
│ ├── server/
│ ├── services/
│ ├── types/
│ └── utils/
│
├── dist/
├── package.json
└── README.md
Roadmap
v0.x
- CRUD API
- Query Engine
- Built-in generators
- Custom schema generation
- Nested objects
- Arrays
- Resource references
- Persistence
- Request validation
- Better Swagger generation
- Seeded data generation
- API authentication
- Response delay simulation
v1.0
- Stable API
- Production-ready documentation
- Improved CLI
- Comprehensive testing
- OpenAPI improvements
Contributing
Contributions are welcome.
If you'd like to improve fake-api, feel free to:
- Fork the repository
- Create a new branch
- Commit your changes
- Open a Pull Request
Bug reports, feature requests, and discussions are always appreciated.
License
This project is licensed under the MIT License.
See the LICENSE file for details.
Support the Project
If you find fake-api useful, consider giving the repository a on GitHub.
It helps the project reach more developers and motivates future development.
Made with by Pabitra Maity