Metadata-Version: 2.4
Name: mockapi-cli
Version: 0.1.0
Summary: A local mock API server generator for fast frontend and integration prototyping.
Author-email: shazeus <efeborazan07@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/shazeus/mockapi-cli
Project-URL: Repository, https://github.com/shazeus/mockapi-cli
Project-URL: Issues, https://github.com/shazeus/mockapi-cli/issues
Keywords: mock-api,api,cli,flask,faker,openapi,testing
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Framework :: Flask
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1
Requires-Dist: faker>=25.0
Requires-Dist: flask>=3.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.7
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Dynamic: license-file

<p align="center">
  <h1 align="center">MockAPI</h1>
  <p align="center">Generate and run local mock API servers from small JSON/YAML specs.</p>
  <p align="center">
    <a href="https://pypi.org/project/mockapi-cli/"><img alt="PyPI" src="https://img.shields.io/pypi/v/mockapi-cli.svg"></a>
    <a href="https://pypi.org/project/mockapi-cli/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/mockapi-cli.svg"></a>
    <a href="https://github.com/shazeus/mockapi-cli/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/shazeus/mockapi-cli.svg"></a>
    <a href="https://github.com/shazeus/mockapi-cli/stargazers"><img alt="Stars" src="https://img.shields.io/github/stars/shazeus/mockapi-cli.svg?style=social"></a>
  </p>
</p>

---

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

```bash
pip install mockapi-cli
```

The installed console command is:

```bash
mockapi --help
```

## Usage

Create a starter spec:

```bash
mockapi init mockapi.yaml --resource users
```

Generate a richer resource:

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

Inspect and validate it:

```bash
mockapi inspect shop.yaml
mockapi validate shop.yaml
```

Preview a route without starting a server:

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

Run the local API:

```bash
mockapi serve shop.yaml --port 8080
```

Export an OpenAPI document:

```bash
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.

```yaml
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](LICENSE).

