fake-api-cli
v0.1.0
Published
Generate realistic fake REST APIs in seconds.
Maintainers
Readme
fake-api-cli
✨ 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-cliOr use directly with NPX
npx fake-api-cli startQuick 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 startOutput
✔ Fake API Server Started
URL:
http://localhost:3000
Resources:
• /users
Swagger:
/docsNow open
http://localhost:3000/usersYou'll instantly have a fully working REST API.
Example Response
[
{
"id": 1,
"name": "John Doe",
"email": "[email protected]",
"city": "London"
},
{
"id": 2,
"name": "Alice Smith",
"email": "[email protected]",
"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=10Sorting
Ascending
GET /users?sort=nameDescending
GET /users?sort=-nameMultiple fields
GET /users?sort=city,-nameFiltering
Equality
GET /users?city=LondonNot equal
GET /users?city_ne=LondonGreater than
GET /products?price_gt=100Greater than or equal
GET /products?price_gte=100Less than
GET /products?price_lt=500Less than or equal
GET /products?price_lte=500IN operator
GET /users?role_in=Admin,ManagerSearch
Search across supported fields.
GET /users?search=johnField Selection
Return only selected fields.
GET /users?fields=id,name,emailResponse
[
{
"id": 1,
"name": "John Doe",
"email": "[email protected]"
}
]💾 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/docsSwagger allows you to:
- Explore endpoints
- Execute requests
- View responses
- Test CRUD operations
No additional configuration required.
🖥 CLI
Start the server
fake-api startUsing NPX
npx fake-api-cli startDevelopment
npm run dev -- startBuild
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
