A lightweight mock API server for PHP developers, designed for rapid prototyping, testing, and API-first development.
MockAPI-PHP enables you to simulate RESTful API responses using JSON or text files without needing a real backend.
Supports OpenAPI 3.0 schema auto-generation based on response data.
Why Use This Tool?
- You want a local mock API server that's simple and fast to set up.
- You prefer file-based mocking (no GUI or code compilation needed).
- You need flexible dynamic responses, custom delays, or error simulations.
- You want to auto-generate OpenAPI specs from actual mock responses.
Ideal For
- PHP developers building or testing frontend-backend integrations.
- QA teams testing API responses without depending on a real server.
- Teams using API-first workflows with tools like Swagger, Prism, Postman.
Overview
- Automatic Endpoint Registration - Scans the
responses/
folder and registers endpoints. - Dynamic Response Loading - Supports JSON and text responses.
- Polling Support - Changes responses based on request count.
- Custom Responses - Uses query parameters for response switching.
- Error Responses - Predefined error messages (e.g., 404).
- Response Delay - Supports delayed responses.
- Custom Hooks - Allows overriding responses dynamically.
- OpenAPI Support - You can automatically generate an OpenAPI 3.0 schema from the response structure you create.
- Logging - Logs requests, responses, authentication, and errors.
- Environment Variable Configuration - Uses
vlucas/phpdotenv
for settings.
Requirements
- PHP 8.3+
- Composer
Unit Tests
Basic functionality is covered by unit tests.
Additional test cases can be added in
tests/MockApiTest.php
.
Run Tests:
php vendor/bin/phpunit
License
This project is released under the MIT License.
Author
- Name: Katsuhiko Maeno
- GitHub: github.com/ka215