json-api-mocker
v3.0.0
Published
A mock server with visual management interface
Downloads
1,403
Maintainers
Readme
JSON API Mocker
A lightweight and flexible mock server with JSON configuration and visual management interface.
✨ Features
- 🚀 Brand new visual management interface
- 🚀 Support both configuration file and UI management
- 🔄 Support all common HTTP methods
- 📝 Automatic data persistence
- 🔍 Built-in pagination support
- 🛠 Customizable response structure
- 🎭 Powerful data mocking with Mock.js
- 📊 Real-time request logs and statistics
- 💡 TypeScript support
📦 Installation
npm install -g json-api-mocker
🚀 Quick Start
The server uses fixed ports:
- API Server: 35728
- Web UI: 35729
- WebSocket: 35730
Method 1: Using Visual Interface (Recommended)
- Create a
data.json
file:
{
"server": {
"port": 35728,
"baseProxy": "/api"
},
"routes": []
}
- Start the server:
# Start server and open browser
json-api-mocker -o
After starting, the browser will automatically open the management interface, where you can:
- Visually create and manage APIs
- View real-time request logs
- Monitor API call statistics
- Debug mock data online
Method 2: Using Configuration File (Compatible with old version)
Create a data.json
file:
{
"server": {
"port": 8080,
"baseProxy": "/api"
},
"routes": [
{
"id": "user-api",
"route": {
"path": "/users",
"methods": {
"get": {
"status": 200,
"response": {
"code": 200,
"message": "success",
"data": {
"list|10": [{
"id": "@id",
"name": "@name",
"email": "@email"
}]
}
}
}
}
}
}
]
}
Then start the server:
json-api-mocker
📖 Configuration
Server Configuration
{
"server": {
"port": 8080, // Server port
"baseProxy": "/api" // API base path
}
}
API Configuration
Each API configuration includes:
{
"id": "unique-id", // API unique identifier
"route": {
"path": "/users", // API path (without base path)
"methods": { // Supported HTTP methods
"get": {
"status": 200, // Response status code
"headers": { // Custom response headers
"Content-Type": "application/json"
},
"response": { // Response data (supports Mock.js syntax)
"code": 200,
"data": {
"name": "@name",
"age": "@integer(18, 60)"
}
}
}
}
}
}
🎮 Visual Interface Features
1. API Management
- Create, edit, and delete APIs
- Support multiple HTTP methods
- Visual response data editor
- Mock.js syntax hints
2. Real-time Logs
- Request path and method
- Response status and duration
- Request parameters recording
- Response data viewing
3. Statistics Dashboard
- Total API count
- Request volume monitoring
- Average response time
- Success rate statistics
🔧 Command Line Options
json-api-mocker [options]
Options:
-p, --port <number> Specify server port (default: 8080)
-c, --config <path> Specify config file path (default: data.json)
-o, --open Auto open management interface
-h, --help Show help information
-v, --version Show version number
📄 License
MIT © [Xiong Haiyin]
🙏 Acknowledgments
- Thanks to all contributors and users
- Special thanks to Mock.js for data mocking support