PHPackages                             raffaelecarelle/dynamic-api-mock-server - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. raffaelecarelle/dynamic-api-mock-server

ActiveProject[API Development](/categories/api)

raffaelecarelle/dynamic-api-mock-server
=======================================

A PHP server that allows creating, saving, and sharing dynamic REST API mocks

20HTML

Since Aug 22Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/raffaelecarelle/Dynamic-API-Mock-Server)[ Packagist](https://packagist.org/packages/raffaelecarelle/dynamic-api-mock-server)[ RSS](/packages/raffaelecarelle-dynamic-api-mock-server/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Dynamic API Mock Server
=======================

[](#dynamic-api-mock-server)

A PHP server that allows creating, saving, and sharing dynamic REST API mocks through a web interface and JSON.

Features
--------

[](#features)

- Create mock endpoints for any HTTP method (GET, POST, PUT, DELETE, PATCH)
- Organize endpoints into projects
- Configure response status codes, headers, and body
- Create dynamic responses with randomized data
- Simulate network delays
- Share mock endpoints with others
- Import and export projects

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- Composer
- Web server (Apache/Nginx) or PHP built-in server
- SQLite/MySQL/PostgreSQL

Installation
------------

[](#installation)

1. Clone the repository:

    ```
    git clone https://github.com/raffaelecarelle/dynamic-api-mock-server.git
    cd dynamic-api-mock-server
    ```
2. Install dependencies:

    ```
    composer install
    ```
3. Configure the environment:

    ```
    cp .env.dist .env
    ```

    Edit the `.env` file to set your database connection and other settings.
4. Run migrations:

    ```
    php bin/migration.php
    ```
5. Start the server:

    ```
    # Using PHP built-in server
    php -S localhost:8080 -t public

    # Or configure your Apache/Nginx to point to the public directory
    ```
6. Access the dashboard:

    ```
    http://localhost:8080/dashboard

    ```

Usage
-----

[](#usage)

### Creating a Project

[](#creating-a-project)

1. Go to the Projects page
2. Click "Create Project"
3. Enter a name and optional description
4. Choose whether the project should be public or private
5. Click "Create Project"

### Creating a Mock Endpoint

[](#creating-a-mock-endpoint)

1. Go to the Mock Endpoints page
2. Click "Create Mock Endpoint"
3. Select your project
4. Configure the endpoint (method, path, status code, etc.)
5. Define the response body and headers
6. Click "Create Mock Endpoint"

### Using a Mock Endpoint

[](#using-a-mock-endpoint)

Your mock endpoint is now available at:

```
http://localhost:8080/mock/{project-name}/{endpoint-path}

```

For example, if your project is named "users-api" and your endpoint path is "/api/users", the URL would be:

```
http://localhost:8080/mock/users-api/api/users

```

### Dynamic Responses

[](#dynamic-responses)

You can create dynamic responses by enabling the "Dynamic Response" option when creating or editing a mock endpoint. This allows you to:

- Generate random numbers, strings, booleans, and dates
- Use request parameters in the response
- Apply conditional logic based on request parameters

Dynamic rules are defined as an array of objects, each with a specific type and target:

#### Random Number

[](#random-number)

```
{
  "type": "random_number",
  "target": "data.id",
  "min": 1,
  "max": 1000
}
```

Generates a random number between `min` and `max` and sets it at the specified `target` path in the response body.

#### Random String

[](#random-string)

```
{
  "type": "random_string",
  "target": "data.token",
  "length": 16,
  "characters": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
}
```

Generates a random string of the specified `length` using the provided `characters`.

#### Random Boolean

[](#random-boolean)

```
{
  "type": "random_boolean",
  "target": "data.active"
}
```

Generates a random boolean value (true or false).

#### Random Date

[](#random-date)

```
{
  "type": "random_date",
  "target": "data.created_at",
  "format": "Y-m-d H:i:s",
  "min_days": -30,
  "max_days": 30
}
```

Generates a random date between `min_days` and `max_days` from the current date, formatted according to `format`.

#### Request Parameter

[](#request-parameter)

```
{
  "type": "request_param",
  "target": "data.user_id",
  "param_type": "path",
  "param_name": "id"
}
```

Uses a parameter from the request in the response. `param_type` can be "path", "query", or "body".

#### Conditional

[](#conditional)

```
{
  "type": "conditional",
  "target": "message",
  "condition": {
    "param_type": "query",
    "param_name": "status",
    "operator": "equals",
    "value": "active"
  },
  "then": "User is active",
  "else": "User is inactive"
}
```

Sets different values based on a condition. Operators include "equals", "not\_equals", "greater\_than", "less\_than", and "contains".

### Sharing Mock Endpoints

[](#sharing-mock-endpoints)

1. Go to the Projects page
2. Click the share button for the project you want to share
3. Copy the share links

Shared mock endpoints can be accessed using:

```
http://localhost:8080/share/{token}/{endpoint-path}

```

API Reference
-------------

[](#api-reference)

The server provides a RESTful API for managing projects and mock endpoints:

### Projects API

[](#projects-api)

- `GET /api/projects` - List all projects
- `GET /api/projects/{id}` - Get a project
- `POST /api/projects` - Create a project
- `PUT /api/projects/{id}` - Update a project
- `DELETE /api/projects/{id}` - Delete a project
- `POST /api/projects/{id}/export` - Export a project
- `POST /api/projects/import` - Import a project
- `GET /api/share/{token}` - Get a project by share token

### Mock Endpoints API

[](#mock-endpoints-api)

- `GET /api/mocks` - List all mock endpoints
- `GET /api/mocks?project_id={id}` - List mock endpoints for a project
- `GET /api/mocks/{id}` - Get a mock endpoint
- `POST /api/mocks` - Create a mock endpoint
- `PUT /api/mocks/{id}` - Update a mock endpoint
- `DELETE /api/mocks/{id}` - Delete a mock endpoint

Testing
-------

[](#testing)

The project includes a test script to verify the API functionality:

```
# Start the server
php -S localhost:8080 -t public

# In another terminal, run the tests
php tests/api_test.php
```

The test script will:

1. Create a test project
2. Create a mock endpoint
3. Test the mock endpoint
4. Update the mock endpoint
5. Test the updated mock endpoint
6. Export the project
7. Test the shared mock endpoint
8. Delete the mock endpoint and project
9. Import the project
10. Clean up

License
-------

[](#license)

MIT

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance44

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/470d7f2b64c268ccd0d73d1d19da604f5049ffdc717170df28ac460d34b8a327?d=identicon)[raffaelecarelle](/maintainers/raffaelecarelle)

---

Top Contributors

[![raffaelecarelle](https://avatars.githubusercontent.com/u/15015792?v=4)](https://github.com/raffaelecarelle "raffaelecarelle (8 commits)")

### Embed Badge

![Health badge](/badges/raffaelecarelle-dynamic-api-mock-server/health.svg)

```
[![Health](https://phpackages.com/badges/raffaelecarelle-dynamic-api-mock-server/health.svg)](https://phpackages.com/packages/raffaelecarelle-dynamic-api-mock-server)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
