json-to-mock-api
v1.1.0
Published
Uma biblioteca CLI para criar servidores REST a partir de arquivos JSON
Maintainers
Readme
Json-To-Mock-Api
A simple CLI library to create REST servers from JSON files or folders with multiple JSON files, featuring automatic integrated Swagger documentation.
✨ Features
- 📋 Automatic Swagger Documentation: Interactive interface to test and document APIs
- 🔧 Mocked Headers: Support for custom response headers for realistic simulations
- 🍪 Mocked Cookies: Support for custom response cookies with advanced options
- 🔄 Inline Schemas: Automatically generated schemas based on real data
- 🚀 Multiple HTTP Methods: Support for GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD
- 📁 File or Folder Mode: Load multiple JSON files or single file
- 🌐 CORS Enabled: Ready for web applications
- 🔗 Path Parameters: Automatic support for parameters like
:id,:userId, etc. - 🏷️ Smart Grouping: Endpoints grouped by folder or file origin
Installation
# Global installation
npm install -g json-to-mock-api
# Or use directly with npx
npx --yes json-to-mock-apiQuick Start
1. Create a JSON file called db.json:
{
"endpoints": {
"users": {
"GET": {
"body": [
{ "id": 1, "name": "John Doe", "email": "[email protected]" },
{ "id": 2, "name": "Jane Smith", "email": "[email protected]" }
],
"headers": {
"X-Total-Count": "2"
},
"cookies": {
"session": "abc123"
}
},
"POST": {
"body": { "id": 3, "name": "New User", "email": "[email protected]" }
}
},
"users/:id": {
"GET": {
"body": { "id": 1, "name": "John Doe", "email": "[email protected]" }
}
}
}
}2. Run the command:
npx --yes json-to-mock-api -f db.json3. Access:
- Swagger UI:
http://localhost:3000/(Interactive documentation) - API Endpoint:
http://localhost:3000/users - OpenAPI Spec:
http://localhost:3000/swagger.json
Usage Modes
File Mode
json-to-mock-api -f db.jsonFolder Mode
json-to-mock-api -d ./dataCLI Options
-f, --file <path>: Path to JSON file-d, --directory <path>: Path to folder with JSON files-p, --port <number>: Server port (default: 3000)-h, --host <string>: Server host (default: localhost)
📚 Complete Documentation
For detailed documentation, advanced features, examples, and guides, visit:
The documentation includes:
- Complete setup guides
- Folder mode examples
- Advanced JSON structures
- Headers and cookies configuration
- Path parameters usage
- Multiple file organization strategies
- Best practices and tips
License
MIT
📖 Read the Full Documentation | 🐛 Report Issues | 💬 Discussions
