PHPackages                             alchemy/rest-bundle - 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. alchemy/rest-bundle

ActiveLibrary[API Development](/categories/api)

alchemy/rest-bundle
===================

Simple REST utility bundle

0.0.5(10y ago)290.4k↓33.3%21MITPHPPHP &gt;=5.4

Since Feb 9Pushed 10y ago10 watchersCompare

[ Source](https://github.com/alchemy-fr/rest-bundle)[ Packagist](https://packagist.org/packages/alchemy/rest-bundle)[ RSS](/packages/alchemy-rest-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (6)Used By (1)

Alchemy - Rest bundle
=====================

[](#alchemy---rest-bundle)

[![License](https://camo.githubusercontent.com/ac885e0ebc1eb1b930b35308f3a9580569ef10ce446e4db6073da1cfbe72d772/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c6368656d792f726573742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/alchemy-fr/rest-bundle/LICENSE)[![Packagist](https://camo.githubusercontent.com/084dbdb38dfa18bcbbb3a77b6d54221be1adcb03fb9deeb7e824ff40eaecf5eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6368656d792f726573742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alchemy/rest-bundle)[![Travis](https://camo.githubusercontent.com/35f55921422c3d3961846c636a587e15ec86290e1ae3d567fc689c936a9654ce/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616c6368656d792d66722f726573742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/alchemy-fr/rest-bundle)[![Scrutinizer Coverage](https://camo.githubusercontent.com/9a2112cac600a1a1bca437c87100afd02a0704f2e3c5ea3b1bd560dd1aef666d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616c6368656d792d66722f726573742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alchemy-fr/rest-bundle/?branch=master)[![Scrutinizer](https://camo.githubusercontent.com/724cfc2ec03bb0df08e6dc2a1dbdd5fe613b1e886000b95d7239e5b09169c251/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616c6368656d792d66722f726573742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alchemy-fr/rest-bundle/)[![Packagist](https://camo.githubusercontent.com/b8f26f6bd40a3b757ec92110905283cdeddb7557be5ed4d6d53132c6de103177/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6368656d792f726573742d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alchemy/rest-bundle/stats)

Features
--------

[](#features)

- Provides automatic date parameter parsing using a predefined format and timezone
- Provides automatic sort and pagination parameter parsing
- Provides standardized error responses in AJAX/JSON contexts

Configuration
-------------

[](#configuration)

Enable the bundle by adding it to the app kernel.

By default, all listeners are enabled. You can add the following section to your `config.yml` to alter the behavior of the listeners:

*Note* The following configuration matches the default settings

```
alchemy_rest:
    dates:
        enabled: true
        format: Y-m-d H:i:s
        timezone: UTC
    exceptions:
        enabled: true
        content-types: [ "application/json" ]
        # Set this to null to use default transformer, or use the key of a service implementing
        # Alchemy\Rest\Response\ExceptionTransformer
        transformer: null
    sort:
        enabled: true
        sort_parameter: sort
        direction_parameter: dir
        mutli_sort_parameter: sorts
    pagination:
        enabled: true
        limit_parameter: limit
        offset_parameter: offset
```

Usage
-----

[](#usage)

### Automatic date parsing

[](#automatic-date-parsing)

To activate date conversions on request parameters, you must explicitly define which parameters will be parsed as dates on a per-route basis in your routing files.

#### Example

[](#example)

Assuming that your requests will contain a `from` and a `to` parameter:

```
my_application.api_route:
    pattern: /api/route
    defaults:
        _dates: [ to, from ]
```

You can now type-hint your controller method as follows:

```
class MyController
{
    public function index(\DateTimeInterface $from, \DateTimeInterface $to)
    {
        // Do something with those dates...
    }
}
```

### Automatic sort and pagination

[](#automatic-sort-and-pagination)

To activate automatic sorting and pagination parameter parsing, you must explicitly activate them on a per-route basis in your routing files.

#### Simple example

[](#simple-example)

```
my_application.api_route:
    pattern: /api/route
    defaults:
        _paginate: true
        _sort: true
```

You can now type-hint your controller method as follows:

```
class MyController
{
    public function index(PaginationOptions $pagination, SortOptions $sort)
    {
        // Do something...
    }
}
```

### Transforming controller results into JSON responses:

[](#transforming-controller-results-into-json-responses)

This listener is always activated. To use it, you must first write a Transformer (see the League/Fractal documentation for information on transformers), and define it as a tagged service in your dependency injection configuration:

```
services:
    my_transformer:
        class: My\Transformer
        tags:
            - { name: alchemy_rest.transformer, alias: my_transformer }
```

Then in your routing file, you need to specify the transformer for a given route:

```
my_application.api_route:
    pattern: /api/route
    defaults:
        _rest:
            decode_request: true # Enabled by default, decodes JSON request bodies into
            encode_response: true
            transform: my_transformer
            list: false
```

You can use the `list` parameter in your route defaults to specifiy whether the controller result should be handled as a list or as a simple object. If your controller returns an instance of PagerFanta (you must include the library in your project as it is an optional dependency), the response will automatically include a `meta` property containing a `pagination` property with the pagination metadata.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.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 ~24 days

Total

5

Last Release

3654d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2437286?v=4)[Benoît Burnichon](/maintainers/bburnichon)[@bburnichon](https://github.com/bburnichon)

![](https://www.gravatar.com/avatar/58d21270e5d40f7ee05bb875b2442496ffd38cec041f7fdcc507b8b040f7e7f8?d=identicon)[thibaud-evaneos](/maintainers/thibaud-evaneos)

![](https://www.gravatar.com/avatar/ee4bb6d5bcc2f9456b41090151c1c8fb288e8949994d965b03b7e25648d663f4?d=identicon)[nmaillat](/maintainers/nmaillat)

---

Top Contributors

[![aztech-dev](https://avatars.githubusercontent.com/u/93562568?v=4)](https://github.com/aztech-dev "aztech-dev (15 commits)")[![bburnichon](https://avatars.githubusercontent.com/u/2437286?v=4)](https://github.com/bburnichon "bburnichon (3 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/alchemy-rest-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/alchemy-rest-bundle/health.svg)](https://phpackages.com/packages/alchemy-rest-bundle)
```

###  Alternatives

[spatie/laravel-fractal

An easy to use Fractal integration for Laravel applications

1.9k15.1M99](/packages/spatie-laravel-fractal)[spatie/fractalistic

A developer friendly wrapper around Fractal

38715.3M8](/packages/spatie-fractalistic)[flugger/laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal and the elegancy of Laravel.

8901.5M5](/packages/flugger-laravel-responder)[yajra/laravel-datatables-fractal

Laravel DataTables Fractal Plugin.

966.9M29](/packages/yajra-laravel-datatables-fractal)[ellipsesynergie/api-response

Simple package to handle response properly in your API

3751.4M20](/packages/ellipsesynergie-api-response)[craftcms/element-api

Create a JSON API for your elements in Craft

503701.3k8](/packages/craftcms-element-api)

PHPackages © 2026

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