Usage
1. Install Dependencies via Composer
composer install
2. Starting the Mock API Server
The mock API server can be started using the following methods.
Recommended: Using
start_server.php
This script automatically applies the PORT
specified
in .env
and clears temporary files.
bash php start_server.php
Manually Using PHP Built-in Server
php -S localhost:3030 -t .
3. API Request Examples
GET Request
curl -X GET http://localhost:3030/api/users
Polling Enabled GET Request
curl -b temp/cookies.txt -c temp/cookies.txt -X GET http://localhost:3030/api/users
POST Request
curl -X POST http://localhost:3030/api/users -H "Content-Type: application/json" -d '{"name": "New User"}'
PUT Request (data updating)
curl -X PUT http://localhost:3030/api/users/1 -H "Content-Type: application/json" -d '{"name": "Updated Name"}'
DELETE Request
curl -X DELETE http://localhost:3030/api/users/1
Custom Response Request
curl -X GET "http://localhost:3030/api/users?mock_response=success"
Check Version
curl -X GET http://localhost:3030/api/version
4. responses/
Configuration
The mock API responses are stored as JSON or text files in the
responses/
directory.
Example Response Structure
responses/ ├── products/ │ ├── get/ │ │ ├── default.json # Default response (used for 3rd to 8th requests and from the 10th request onward) │ │ ├── 1.json # Response for the 1st request │ │ ├── 2.json # Response for the 2nd request │ │ └── 9.json # Response for the 9th request │ ├── post/ │ │ ├── success.json # Response for a successful product creation │ │ └── 400.json # Response for a validation error │ ├── patch/ │ │ └── success.json # Response for a successful product update │ ├── delete/ │ │ └── success.json # Response for a successful product deletion │ └─… └─…
Error Response Configuration Example:
responses/errors/404.json
{ "error": "Resource not found", "code": 404 }
Example:
responses/errors/500.txt
Internal Server Error