PHPackages                             tbbc/rest-util - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. tbbc/rest-util

ActiveLibrary[HTTP &amp; Networking](/categories/http)

tbbc/rest-util
==============

Some useful classes for handling certain aspects of a REST(ful) API.

v1.0.0(11y ago)16220.7k↓41.7%41MITPHPPHP &gt;=5.3.3

Since May 28Pushed 3y ago5 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (1)

The Big Brains Company - Rest Util
==================================

[](#the-big-brains-company---rest-util)

[![Build Status](https://camo.githubusercontent.com/6560c8f7e7096538abb86cbe726e6301168b93caa14f90157d6de4e5ecc82ee5/68747470733a2f2f7472617669732d63692e6f72672f546865426967427261696e73436f6d70616e792f726573742d7574696c2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/TheBigBrainsCompany/rest-util)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/7fcd1b70d9bce23cd031aa9ada89c54eda93ed95e3c347d231ab016e3b8fe672/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f546865426967427261696e73436f6d70616e792f726573742d7574696c2f6261646765732f7175616c6974792d73636f72652e706e673f733d32353866313565316330343331306166356266616534656535356130353131356139663835376637)](https://scrutinizer-ci.com/g/TheBigBrainsCompany/rest-util/)

Rest util library for PHP.

This library implement some useful util classes for resolving recurrent issues in Rest(ful) APIs (i.e: Error handling).

Quick Start
-----------

[](#quick-start)

Table of contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Getting started](#getting-started)
3. [Usage](#usage)
4. [Run the test](#run-the-test)
5. [Contributing](#contributing)
6. [Requirements](#requirements)
7. [Authors](#authors)
8. [License](#license)

Description
-----------

[](#description)

Rest utilitary library for PHP

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

[](#installation)

Using [Composer](http://getcomposer.org/), just `$ composer require tbbc/rest-util` package or:

```
{
  "require": {
    "tbbc/rest-util": "dev-master"
  }
}
```

Usage
-----

[](#usage)

Converting Exception into Error object:

1\. First you have to define an `ExceptionMapping`, for the sake of the example, we use `PHP`, but a `YamlLoader` is also available:

```
// Exception mapping configuration
$invalidArgumentExceptionMapping = new ExceptionMapping(array(
    'exceptionClassName'   => '\InvalidArgumentException',
    'factory'              => 'default',
    'httpStatusCode'       => 400,
    'errorCode'            => 400101,
    'errorMessage'         => null,
    'errorExtendedMessage' => 'Extended message',
    'errorMoreInfoUrl'     => 'http://api.my.tld/doc/error/400101',
));
```

2\. The `ExceptionMapping` must be added to `ExceptionMap`:

```
$exceptionMap = new ExceptionMap();
$exceptionMap->add($invalidArgumentExceptionMapping);
```

3\. We plug the `ErrorResolver` with an ErrorFactory, a `DefaultErrorFactory` is bundled within the lib:

```
// Error resolver initialization
$errorResolver       = new ErrorResolver($exceptionMap);
$defaultErrorFactory = new DefaultErrorFactory();
$errorResolver->registerFactory($defaultErrorFactory);
```

4\. Resolve error!

```
$exception = new \InvalidArgumentException('This is an invalid argument exception');
$error     = $errorResolver->resolve($exception);
```

5\. The `$error` variable is now assigned an `ErrorInterface` object which implements a `toArray()` method to allow easy serialization method of your choice:

```
print_r($error->toArray());
/* will output
Array
(
    [http_status_code] => 400
    [code]             => 400101
    [message]          => This is an invalid argument exception.
    [extended_message] => Extended message
    [more_info_url]    => http://api.my.tld/doc/error/400101
)
*/

echo json_encode($error->toArray());
/* And voilà! You get a ready to use json normalized error response body
{
    "http_status_code": 400,
    "code":             400101,
    "message":          "This is an invalid argument exception.",
    "extended_message": "Extended message",
    "more_info_url":    "http:\/\/api.my.tld\/doc\/error\/400101"
}
*/
```

For more concrete real life usage, take a look at our bundle for integrating the lib into a Symfony application: [TbbcRestUtilBundle](https://github.com/TheBigBrainsCompany/TbbcRestUtilBundle).

Run the test
------------

[](#run-the-test)

First make sure you have installed all the dependencies, run:

`$ composer install --dev`

then, run the test from within the root directory:

`$ vendor/bin/phpunit`

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

[](#contributing)

1. Take a look at the [list of issues](http://github.com/TheBigBrainsCompany/rest-util/issues).
2. Fork
3. Write a test (for either new feature or bug)
4. Make a PR

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

[](#requirements)

- PHP 5.3+

Authors
-------

[](#authors)

- Boris Guéry -  -
- Benjamin Dulau -

License
-------

[](#license)

`The Big Brains Company - Rest Util` is licensed under the MIT License - see the LICENSE file for details

[![The Big Brains Company - Logo](https://camo.githubusercontent.com/1f1a60532f95341dbae519e720db83ffb265a06669dba5da82ca5d6f728180be/687474703a2f2f746262632d76616c69642e746865626967627261696e73636f6d70616e792e636f6d2f6173736574732f696d616765732f6c6f676f2d746262632e706e67)](http://thebigbrainscompany.com)

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

4374d ago

### Community

Maintainers

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

---

Top Contributors

[![benjamindulau](https://avatars.githubusercontent.com/u/430689?v=4)](https://github.com/benjamindulau "benjamindulau (16 commits)")[![armetiz](https://avatars.githubusercontent.com/u/1119250?v=4)](https://github.com/armetiz "armetiz (2 commits)")[![borisguery](https://avatars.githubusercontent.com/u/345495?v=4)](https://github.com/borisguery "borisguery (2 commits)")

---

Tags

apirestrestful

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tbbc-rest-util/health.svg)

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

###  Alternatives

[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[arhitector/yandex

PHP SDK для работы с некоторыми сервисами яндекса (Яндекс.Диск, Yandex.Disk)

13082.9k5](/packages/arhitector-yandex)[tbbc/rest-util-bundle

Bundle for integrating tbbc/rest-util lib in a Symfony application.

30205.4k1](/packages/tbbc-rest-util-bundle)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4540.0k](/packages/ismaeltoe-osms)

PHPackages © 2026

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