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.1.0(1mo ago)31.6k↓86.7%[1 issues](https://github.com/rrd108/cakephp-json-api-exception/issues)MITPHPPHP &gt;=8.0CI failing

Since Oct 23Pushed 1mo 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 today

READMEChangelog (9)Dependencies (4)Versions (13)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)

Supports CakePHP 5.0–5.3+. On CakePHP 5.3+ the plugin class auto-detection uses `JsonApiExceptionPlugin` — no change required in your `Application.php`.

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

47

—

FairBetter than 93% of packages

Maintenance84

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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 ~166 days

Recently: every ~384 days

Total

11

Last Release

49d 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 (32 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

[cakephp/debug_kit

CakePHP Debug Kit

86314.7M171](/packages/cakephp-debug-kit)[cakephp/bake

Bake plugin for CakePHP

11212.0M202](/packages/cakephp-bake)[dereuromark/cakephp-queue

The Queue plugin for CakePHP provides deferred task execution.

308954.9k25](/packages/dereuromark-cakephp-queue)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M44](/packages/dereuromark-cakephp-ide-helper)[dereuromark/cakephp-tools

A CakePHP plugin containing lots of useful and reusable tools

3361.0M51](/packages/dereuromark-cakephp-tools)[dereuromark/cakephp-tinyauth

A CakePHP plugin to handle user authentication and authorization the easy way.

131240.2k13](/packages/dereuromark-cakephp-tinyauth)

PHPackages © 2026

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