Generate and run local mock API servers from small JSON/YAML specs.
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.
pip install mockapi-cliThe installed console command is:
mockapi --helpCreate a starter spec:
mockapi init mockapi.yaml --resource usersGenerate a richer resource:
mockapi generate shop.yaml --resource products --field id:id --field name:word --field price:float --field in_stock:boolInspect and validate it:
mockapi inspect shop.yaml
mockapi validate shop.yamlPreview 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 8080Export an OpenAPI document:
mockapi openapi shop.yaml --output openapi.json| 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 |
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 }}).
MIT License. See LICENSE.