1.0.0 • Published 5 months ago

snapsrv4u v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

🚀 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

TypeDescriptionOptions
numberRandom numbermin, max
stringRandom stringmin, max (length)
booleanRandom true/false-
dateRandom datefrom, to
nameRandom full name-
emailRandom email address-
uuidRandom UUID-
idNumeric ID with paddingzeros (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 generate
  • min: Minimum value/length
  • max: Maximum value/length
  • zeros: Number of digits for IDs
  • from: Start date for date ranges
  • to: End date for date ranges
1.0.0

5 months ago

0.0.13

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago