Module quick_mock

Module quick_mock 

Source
Expand description

Quick mock generation utilities Quick Mock Mode

Provides instant REST API mocking from JSON files with auto-route detection. Perfect for rapid prototyping and testing without configuration.

§Features

  • Zero configuration setup
  • Auto-detection of routes from JSON keys
  • Dynamic data generation with tokens ($random, $faker, $ai)
  • Full CRUD operations on all detected resources
  • Pagination support with page and limit parameters
  • Filtering support with any field as query parameter
  • Sorting support with sort=field:direction syntax

§Example

{
  "users": [
    {"id": "$random.uuid", "name": "$faker.name", "email": "$faker.email", "role": "admin"}
  ],
  "posts": [
    {"id": "$random.int", "title": "Sample Post", "content": "$faker.paragraph"}
  ]
}

§Auto-generated Endpoints

  • GET /users - List all users
  • GET /users/:id - Get single user
  • POST /users - Create user
  • PUT /users/:id - Update user
  • DELETE /users/:id - Delete user
  • Same for /posts

§Query Parameters

  • ?page=2&limit=10 - Pagination (page is 1-indexed, limit 1-1000)
  • ?role=admin - Filter by field value
  • ?sort=name:asc - Sort by field (asc/desc)
  • ?role=admin&sort=name:desc&page=1&limit=20 - Combined filtering, sorting, and pagination

§Response Format

List endpoints return:

{
  "data": [...],
  "pagination": {
    "page": 1,
    "limit": 50,
    "total": 100,
    "totalPages": 2,
    "hasNext": true,
    "hasPrev": false
  }
}

Structs§

ListQueryParams
Query parameters for list endpoints
QuickMockState
Quick mock state holding the data store

Functions§

build_quick_router
Build a router with auto-detected routes from quick mock state