3.0.0 • Published 10 months ago
json-api-mocker v3.0.0
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: 1. Visually create and manage APIs 2. View real-time request logs 3. Monitor API call statistics 4. 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
3.0.0
10 months ago
2.3.1
10 months ago
2.3.0
10 months ago
2.2.2
10 months ago
2.2.1
10 months ago
2.2.0
10 months ago
2.1.0
10 months ago
2.0.4
10 months ago
2.0.3
10 months ago
2.0.2
10 months ago
2.0.1
10 months ago
2.0.0
10 months ago
1.2.7
10 months ago
1.2.6
10 months ago
1.2.5
10 months ago
1.2.3
10 months ago
1.2.2
10 months ago
1.2.1
10 months ago
1.2.0
10 months ago
1.1.0
10 months ago
1.0.3
10 months ago
1.0.2
10 months ago
1.0.1
10 months ago
1.0.0
10 months ago