Skip to content

shazeus/mockapi-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MockAPI

Generate and run local mock API servers from small JSON/YAML specs.

PyPI Python License Stars


MockAPI is a terminal-first mock API generator for frontend development, integration testing, demos, and API contract prototyping. It turns compact JSON/YAML specs into working Flask routes, can generate REST-style resource specs with realistic Faker data, previews route responses without starting a server, validates duplicate routes and status codes, and exports OpenAPI documents for downstream tooling.

  • Spec-driven mock servers - run GET, POST, PUT, PATCH, DELETE, OPTIONS, and HEAD routes from JSON or YAML.
  • REST resource generation - scaffold list, detail, create, update, patch, and delete endpoints with realistic sample data.
  • Dynamic response templates - use placeholders such as {{ name }}, {{ uuid }}, {{ body.email }}, and {{ path.id }}.
  • OpenAPI export - turn a mock spec into a portable OpenAPI 3 document.
  • Fast local previews - inspect, validate, and request mock responses directly from the CLI.
  • Clean terminal output - Rich tables, panels, syntax highlighting, and readable validation errors.

Installation

pip install mockapi-cli

The installed console command is:

mockapi --help

Usage

Create a starter spec:

mockapi init mockapi.yaml --resource users

Generate a richer resource:

mockapi generate shop.yaml --resource products --field id:id --field name:word --field price:float --field in_stock:bool

Inspect and validate it:

mockapi inspect shop.yaml
mockapi validate shop.yaml

Preview a route without starting a server:

mockapi request shop.yaml GET /products/42
mockapi request shop.yaml POST /products --body '{"name":"Keyboard","price":89.9}'

Run the local API:

mockapi serve shop.yaml --port 8080

Export an OpenAPI document:

mockapi openapi shop.yaml --output openapi.json

Commands

Command Description Example
mockapi init [path] Create a starter YAML spec. mockapi init mockapi.yaml --resource users
mockapi generate <output> Generate CRUD-style REST routes with fake data. mockapi generate api.yaml --resource orders --count 10
mockapi serve <spec> Start a Flask mock API server. mockapi serve api.yaml --port 8080
mockapi inspect <spec> Show API metadata and route summaries. mockapi inspect api.yaml
mockapi validate <spec> Validate methods, paths, status codes, and duplicate routes. mockapi validate api.yaml
mockapi sample <resource> Generate fake records as JSON or a table. mockapi sample users --field email:email --count 3
mockapi request <spec> <method> <path> Render a mock response without a server. mockapi request api.yaml GET /orders/1
mockapi openapi <spec> Export an OpenAPI 3 document. mockapi openapi api.yaml -o openapi.json
mockapi export <spec> Normalize and convert a spec to JSON or YAML. mockapi export api.yaml --to json -o api.json

Configuration

MockAPI specs are plain YAML or JSON files. A route includes an HTTP method, path, status code, optional headers, and response body.

name: Example API
version: 1.0.0
cors: true
routes:
  - method: GET
    path: /users/{id}
    status: 200
    response:
      id: "{{ path.id }}"
      name: "{{ name }}"
      email: "{{ email }}"
  - method: POST
    path: /users
    status: 201
    response:
      id: "{{ uuid }}"
      email: "{{ body.email }}"

Supported placeholder sources include Faker fields ({{ name }}, {{ email }}, {{ city }}), generated values ({{ uuid }}, {{ int }}, {{ bool }}), request body fields ({{ body.name }}), query parameters ({{ query.page }}), headers ({{ headers.Authorization }}), and route parameters ({{ path.id }}).

License

MIT License. See LICENSE.

About

A local mock API server generator for fast frontend and integration prototyping.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages