1.0.0 • Published 5 months ago
snapsrv4u v1.0.0
🚀 Mock API Server
A powerful and flexible mock API server that automatically generates realistic data based on your specifications using Faker.js
📦 Installation
npm install snapsrv4u
🚀 Quick Start
import { MockApiServer } from 'snapsrv4u';
const server = new MockApiServer(3000);
server.addRoute('/api/users', {
method: 'GET',
count: 10,
properties: {
id: { type: 'id', zeros: 5 },
name: { type: 'name' },
email: { type: 'email' }
}
});
server.start();
🎯 Features
- 🔥 Zero configuration required
- 🎲 Automatic data generation
- 📊 Configurable data types and ranges
- 🛠 Customizable response structure
- ⚡️ Fast and lightweight
📝 API Reference
Creating a Server
const server = new MockApiServer(port); // port defaults to 3000
Adding Routes
server.addRoute(path, config);
Config Options
method
: HTTP method ('GET', 'POST', etc.)count
: Number of items to generate (1 for single object, >1 for array)properties
: Object describing the data structure
📚 Supported Data Types
Type | Description | Options |
---|---|---|
number | Random number | min , max |
string | Random string | min , max (length) |
boolean | Random true/false | - |
date | Random date | from , to |
name | Random full name | - |
email | Random email address | - |
uuid | Random UUID | - |
id | Numeric ID with padding | zeros (padding length) |
💡 Examples
server.addRoute('/api/person', {
method: 'GET',
count: 1,
properties: 'person',
});
🔧 Configuration Options
Each property can have these configurations:
type
: (Required) Data type to generatemin
: Minimum value/lengthmax
: Maximum value/lengthzeros
: Number of digits for IDsfrom
: Start date for date rangesto
: End date for date ranges