PHPackages                             aliengen/pachyderm - 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. aliengen/pachyderm

ActiveLibrary[API Development](/categories/api)

aliengen/pachyderm
==================

A Micro PHP framework for APIs

v1.1(6mo ago)52.2k↓80%4MITPHPPHP &gt;=8.4

Since Dec 1Pushed 5mo ago3 watchersCompare

[ Source](https://github.com/AlienGen/pachyderm)[ Packagist](https://packagist.org/packages/aliengen/pachyderm)[ RSS](/packages/aliengen-pachyderm/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)DependenciesVersions (6)Used By (0)

Pachyderm - A Micro PHP Framework for APIs
==========================================

[](#pachyderm---a-micro-php-framework-for-apis)

Pachyderm is a lightweight PHP framework designed for building APIs with ease. It provides a simple and flexible way to manage routes, middleware, and HTTP requests.

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
    - [Motivation](#motivation)
    - [Goals](#goals)
    - [Features](#features)
- [Getting Started](#getting-started)
    - [Installation](#installation)
    - [Usage](#usage)
        - [Simple Example](#simple-example)
        - [Setting Up a Controller](#setting-up-a-controller)
- [Middleware](#middleware)
    - [Registering Global Middleware](#registering-global-middleware)
    - [Adding and Removing Middleware for Specific Routes](#adding-and-removing-middleware-for-specific-routes)
- [Routes](#routes)
    - [Supported HTTP Methods](#supported-http-methods)
- [Services](#services)
    - [Registering a Service](#registering-a-service)
    - [Using a Registered Service](#using-a-registered-service)
    - [Direct Instantiation of Db](#direct-instantiation-of-db)
- [Exception Handling](#exception-handling)
    - [Using ExceptionHandlerMiddleware](#using-exceptionhandlermiddleware)
    - [Existing Exceptions](#existing-exceptions)
- [Additional Information](#additional-information)
- [License](#license)

Introduction
------------

[](#introduction)

### Motivation

[](#motivation)

Pachyderm began as an internal training project at AlienGen, aimed at deepening our understanding of framework fundamentals and showcasing PHP's capabilities. As we developed numerous microservices, we recognized the need for a more robust solution than single-file scripts for main endpoints. Pachyderm emerged as a micro framework designed to be both simple and user-friendly, offering a lightweight alternative to larger frameworks like Laravel or Symfony.

We adhere to the KISS (Keep It Simple, Stupid) principle, ensuring our code remains straightforward and comprehensible. The framework's components are extensible, allowing for customization to meet specific needs. By minimizing external dependencies, Pachyderm remains compact and tailored.

Our development approach aligns with the 12-factor app principles, ensuring the framework is built to support these best practices.

### Goals

[](#goals)

- **Developer Experience**: Prioritize ease of use, enabling developers to concentrate on business logic with minimal code.
- **Simplicity**: Maintain clear and understandable code for developers.
- **Extensibility**: Allow customization to suit individual project requirements.
- **Lightweight**: Core framework avoids external dependencies, though projects can incorporate any necessary libraries.

### Features

[](#features)

- Routing
- Service Container
- Validation
- Middleware
- Exception Handling
- Response Management

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

To install Pachyderm, use Composer:

```
composer require aliengen/pachyderm
```

### Usage

[](#usage)

#### Simple Example

[](#simple-example)

```
use Pachyderm\Dispatcher;
use Pachyderm\Exchange\Response;

$dispatcher = new Dispatcher();

// Declare a new GET endpoint
$dispatcher->get('/my_endpoint', function() {
    return Response::success(['success' => true]);
});

// Dispatch the request
$dispatcher->dispatch();
```

#### Setting Up a Controller

[](#setting-up-a-controller)

To create a controller, you need to set up a dispatcher and register your middleware and routes.

```
use Pachyderm\Dispatcher;
use Pachyderm\Middleware\MiddlewareManager;
use Pachyderm\Middleware\PreflightRequestMiddleware;
use Pachyderm\Middleware\TimerMiddleware;
use Pachyderm\Middleware\DbSessionMiddleware;
use Pachyderm\Middleware\SessionMiddleware;
use Pachyderm\Middleware\SessionAuthMiddleware;
use Pachyderm\Middleware\JSONEncoderMiddleware;
use Pachyderm\Exchange\Response;

/*
 * Instantiate the dispatcher with a base URL and middleware manager.
 */
$dispatcher = new Dispatcher('/api',  new MiddlewareManager());

/* Declaration of the middleware. */
$dispatcher->registerMiddlewares([
    JSONEncoderMiddleware::class,
    PreflightRequestMiddleware::class,
    SessionMiddleware::class,
    SessionAuthMiddleware::class,
    TimerMiddleware::class,
    DbSessionMiddleware::class
]);

/**
 * Declaration of the routes.
 */

$dispatcher->get('/my_endpoint', function() {
    return Response::success(['success' => true]);
});

$dispatcher->post('/my_post_endpoint', function($data) {
    return Response::success(['success' => true]);
});

/**
 * Dispatch the request.
 */
$dispatcher->dispatch();
```

### Middleware

[](#middleware)

Middleware in Pachyderm allows you to process requests and responses. You can register global middleware or specific middleware for individual routes.

#### Registering Global Middleware

[](#registering-global-middleware)

Example of registering global middleware:

```
$dispatcher->registerMiddlewares([
    JSONEncoderMiddleware::class,
    PreflightRequestMiddleware::class,
    // Add more middleware as needed
]);
```

#### Adding and Removing Middleware for Specific Routes

[](#adding-and-removing-middleware-for-specific-routes)

You can add middleware that should only be applied to specific routes, or remove global middleware from specific routes.

Example of adding and removing middleware for a route:

```
$dispatcher->get('/my_endpoint', function() {
    return Response::success(['success' => true]);
},
[
    // Local middleware to be applied only to this route
    CustomMiddleware::class
],
[
    // Global middleware to be excluded from this route
    JSONEncoderMiddleware::class
]);
```

- **Local Middleware**: Specify middleware that should only be applied to the route by passing an array of middleware classes as the third parameter.
- **Blacklist Middleware**: Specify global middleware that should be excluded from the route by passing an array of middleware classes as the fourth parameter.

### Routes

[](#routes)

Pachyderm supports various HTTP methods such as GET, POST, PUT, DELETE, etc. You can define routes and their corresponding handlers.

#### Supported HTTP Methods

[](#supported-http-methods)

- **GET**: Used to retrieve data from the server.

    ```
    $dispatcher->get('/example', function() {
        return Response::success(['message' => 'Hello, World!']);
    });
    ```
- **POST**: Used to send data to the server.

    ```
    $dispatcher->post('/submit', function($data) {
        // Process $data
        return Response::success(['status' => 'Data submitted successfully']);
    });
    ```
- **PUT**: Used to update existing data on the server.

    ```
    $dispatcher->put('/update/{id}', function($id, $data) {
        // Update data with $id
        return Response::success(['status' => 'Data updated successfully']);
    });
    ```
- **DELETE**: Used to delete data from the server.

    ```
    $dispatcher->delete('/delete/{id}', function($id) {
        // Delete data with $id
        return Response::success(['status' => 'Data deleted successfully']);
    });
    ```
- **OPTIONS**: Used to describe the communication options for the target resource.

    ```
    $dispatcher->request('OPTIONS', '/options', function() {
        return Response::success(['methods' => 'GET, POST, PUT, DELETE']);
    });
    ```
- **HEAD**: Used to retrieve the headers of a resource.

    ```
    $dispatcher->request('HEAD', '/headers', function() {
        return Response::success(['methods' => 'GET, POST, PUT, DELETE']);
    });
    ```

### Services

[](#services)

Pachyderm provides a simple service container for managing service instances. You can register services as closures and retrieve them by name.

#### Registering a Service

[](#registering-a-service)

To register a service, use the `Service::set` method. For example, to register the `Db` class as a service:

```
use Pachyderm\Service;
use Pachyderm\Db;

Service::set('db', function() {
    return new Db([
        'host' => 'your_db_host',
        'username' => 'your_db_username',
        'password' => 'your_db_password',
        'database' => 'your_db_name'
    ]);
});
```

#### Using a Registered Service

[](#using-a-registered-service)

To retrieve and use a registered service, use the `Service::get` method. For example, to use the `Db` service:

```
$db = Service::get('db');
$results = $db->findAll('users');
```

#### Direct Instantiation of Db

[](#direct-instantiation-of-db)

If you prefer to create a new instance of the `Db` class directly, you can do so as follows:

```
use Pachyderm\Db;

// Define your database configuration parameters
$parameters = [
    'host' => 'your_db_host',
    'username' => 'your_db_username',
    'password' => 'your_db_password',
    'database' => 'your_db_name'
];

// Create a new instance of the Db class
$db = new Db($parameters);

// Use the $db instance to perform database operations
$results = $db->findAll('users');
```

This approach allows you to have multiple instances of the `Db` class with different configurations if needed.

### Exception Handling

[](#exception-handling)

Pachyderm provides a way to handle exceptions that occur during the execution of your application using the `ExceptionHandlerMiddleware`. This middleware is designed to catch exceptions of type `AbstractHTTPException` and return a structured response.

#### Using ExceptionHandlerMiddleware

[](#using-exceptionhandlermiddleware)

To use the `ExceptionHandlerMiddleware`, you need to register it with your dispatcher. This middleware will catch any exceptions that occur during the request processing and handle them appropriately.

Here's an example of how to register and use the `ExceptionHandlerMiddleware`:

```
use Pachyderm\Dispatcher;
use Pachyderm\Middleware\MiddlewareManager;
use Pachyderm\Middleware\ExceptionHandlerMiddleware;

$dispatcher = new Dispatcher('/api', new MiddlewareManager());

// Register the ExceptionHandlerMiddleware
$dispatcher->registerMiddlewares([
    ExceptionHandlerMiddleware::class,
    // Other middlewares...
]);

// Define a route that throws a BadRequestException
$dispatcher->get('/example', function() {
    // Simulate a condition that causes a bad request
    $condition = false;
    if (!$condition) {
        throw new BadRequestException('Invalid request parameters.');
    }
    return Response::success(['success' => true]);
});

// Dispatch the request
$dispatcher->dispatch();
```

#### Existing Exceptions

[](#existing-exceptions)

The following exceptions implement the `AbstractHTTPException` and can be used to handle specific HTTP error scenarios:

- **BadRequestException**: Represents a 400 Bad Request error.
- **UnauthenticatedException**: Represents a 401 Unauthorized error.
- **NotFoundException**: Represents a 404 Not Found error.

These exceptions can be thrown within your route handlers to trigger the `ExceptionHandlerMiddleware` and return appropriate HTTP error responses.

Additional Information
----------------------

[](#additional-information)

- **Configuration**: Use the `Config` class to manage application configurations.
- **Database**: The `Db` class provides methods for database interactions, including transactions and queries.
- **Error Handling**: Custom exceptions are available for handling different error scenarios.

For more detailed documentation, please refer to the source code and comments within the files.

License
-------

[](#license)

Pachyderm is licensed under the MIT License. See the LICENSE file for more details.

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance68

Regular maintenance activity

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 85.3% 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.

###  Release Activity

Cadence

Every ~1588 days

Total

2

Last Release

209d ago

PHP version history (2 changes)v1.0PHP &gt;=5.6.0

v1.1PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/711667?v=4)[Timothé Mermet-Buffet](/maintainers/mermetbt)[@mermetbt](https://github.com/mermetbt)

---

Top Contributors

[![mermetbt](https://avatars.githubusercontent.com/u/711667?v=4)](https://github.com/mermetbt "mermetbt (58 commits)")[![pportelette](https://avatars.githubusercontent.com/u/20822596?v=4)](https://github.com/pportelette "pportelette (7 commits)")[![ortonomy](https://avatars.githubusercontent.com/u/6688676?v=4)](https://github.com/ortonomy "ortonomy (1 commits)")[![pjouglet](https://avatars.githubusercontent.com/u/13447879?v=4)](https://github.com/pjouglet "pjouglet (1 commits)")[![westwoodworm](https://avatars.githubusercontent.com/u/124873738?v=4)](https://github.com/westwoodworm "westwoodworm (1 commits)")

---

Tags

apicomposerdependency-injectionframeworkhttpkisslightweightmicro-frameworkmiddlewarephppsrrest-apiroutingservice-container

### Embed Badge

![Health badge](/badges/aliengen-pachyderm/health.svg)

```
[![Health](https://phpackages.com/badges/aliengen-pachyderm/health.svg)](https://phpackages.com/packages/aliengen-pachyderm)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35916.4M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24016.2M20](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172445.0k15](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93459.5k6](/packages/botman-driver-telegram)

PHPackages © 2026

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