PHPackages                             rrd108/cakephp-json-api-exception - 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. rrd108/cakephp-json-api-exception

ActiveCakephp-plugin[API Development](/categories/api)

rrd108/cakephp-json-api-exception
=================================

JsonApiException plugin for CakePHP

1.0.0(2y ago)21.6k↓50%[1 issues](https://github.com/rrd108/cakephp-json-api-exception/issues)MITPHPPHP &gt;=8.0

Since Oct 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/rrd108/cakephp-json-api-exception)[ Packagist](https://packagist.org/packages/rrd108/cakephp-json-api-exception)[ RSS](/packages/rrd108-cakephp-json-api-exception/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (12)Used By (0)

JsonApiException plugin for CakePHP
===================================

[](#jsonapiexception-plugin-for-cakephp)

Make your CakePHP 5 JSON REST API response more descriptive on errors.

For CakePHP 4 support use the [CakePHP 4 branch](https://github.com/rrd108/cakephp-json-api-exception/tree/cakephp4)

If you want a simple solution for token authentication for a CakePHP JSON REST API, then check this: [CakePHP API Token Authenticator](https://github.com/rrd108/api-token-authenticator)

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

[](#installation)

You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).

The recommended way to install is:

```
composer require rrd108/cakephp-json-api-exception

```

Then, to load the plugin either run the following command:

```
bin/cake plugin load JsonApiException

```

or manually add the following line to your app's `src/Application.php` file's `bootstrap()` function:

```
$this->addPlugin('JsonApiException');
```

done :)

How to use
----------

[](#how-to-use)

Assuming you have a CakePHP JSON REST API and you want to have more informative error messages and proper response codes.

```
// for example in /src/Controller/UsersController.php slightly change the baked add function
use JsonApiException\Error\Exception\JsonApiException;

public function add()
{
    $user = $this->Users->newEmptyEntity();
    if ($this->request->is('post')) {
        $user = $this->Users->patchEntity($user, $this->request->getData());
        if (!$this->Users->save($user)) {
            throw new JsonApiException($user, 'Save failed');
            // throw new JsonApiException($user, 'Save failed', 418);   // you can set the response's status code in the 3rd parameter
        }
    }
    $this->set(compact('user'));
    $this->viewBuilder()->setOption('serialize', ['user']);
}
```

If the save failed you will get a response like this.

```
{
  "message": "Save failed",
  "url": "/users.json",
  "line": 12,
  "errorCount": 1,
  "errors": {
    "password": {
      "_required": "This field is required"
    }
  }
}
```

You can us it with an array of entities also.

```
// for example in /src/Controller/UsersController.php slightly change the baked add function
use JsonApiException\Error\Exception\JsonApiException;

public function bulkAdd()
{
    $users = $this->Users->newEntities($this->request->getData());
    if (!$this->Users->saveMany($users)) {
        throw new JsonApiException($users, 'Errors in request data');
    }
    $this->set(compact('users'));
    $this->viewBuilder()->setOption('serialize', ['users']);
}
```

If the save failed you will get a response like this. As at this point we do not have an `id` for the entity, the error messages can not contain it. So an empty array will be present in the `errors` array if an entity does not have any errors. So the number of the entity will match the number of the error entries, entity #3's error message will be the third element of the error array.

```
{
  "message": "Errors in request data",
  "url": "/users.json",
  "line": 12,
  "errorCount": 2,
  "errors": [
    {
      "name": {
        "_empty": "name is required"
      }
    },
    {
      "name": {
        "_empty": "name is required"
      }
    }
  ]
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~83 days

Recently: every ~155 days

Total

10

Last Release

919d ago

Major Versions

0.4.0 → 1.0.02023-11-11

PHP version history (2 changes)0.0.1PHP &gt;=7.2

0.4.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f115ed63db719bb70b5f9f74a077e5dba1e3962d394f63bde914de8f64171d8?d=identicon)[rrd](/maintainers/rrd)

---

Top Contributors

[![rrd108](https://avatars.githubusercontent.com/u/3147489?v=4)](https://github.com/rrd108 "rrd108 (30 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rrd108-cakephp-json-api-exception/health.svg)

```
[![Health](https://phpackages.com/badges/rrd108-cakephp-json-api-exception/health.svg)](https://phpackages.com/packages/rrd108-cakephp-json-api-exception)
```

###  Alternatives

[friendsofcake/crud-json-api

Listener for building CakePHP Crud APIs following the JSON API specification.

58445.4k3](/packages/friendsofcake-crud-json-api)[alt3/cakephp-swagger

Instant Swagger documentation for your CakePHP 4.x APIs

64197.3k3](/packages/alt3-cakephp-swagger)[cnizzardini/cakephp-swagger-bake

Automatically generate OpenApi, Swagger, and Redoc documentation from your existing cakephp project

60171.2k4](/packages/cnizzardini-cakephp-swagger-bake)[bcrowe/cakephp-api-pagination

CakePHP 4 plugin that injects pagination information into API responses.

3953.5k1](/packages/bcrowe-cakephp-api-pagination)[gourmet/social-meta

Adds Facebook Open Graph and Twitter Cards support to CakePHP 3.x

255.1k](/packages/gourmet-social-meta)

PHPackages © 2026

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