PHPackages                             benycode/slim-jad-middleware - 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. [Framework](/categories/framework)
4. /
5. benycode/slim-jad-middleware

ActiveLibrary[Framework](/categories/framework)

benycode/slim-jad-middleware
============================

Jad (jsonapi.org) implementation in the slim 4

v1.0.2(3y ago)013PHPPHP ^8.0

Since Sep 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/benycode/slim-jad-middleware)[ Packagist](https://packagist.org/packages/benycode/slim-jad-middleware)[ RSS](/packages/benycode-slim-jad-middleware/feed)WikiDiscussions main Synced today

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

[JAD](https://github.com/oligus/jad) (jsonapi.org) implementation in Slim 4 framework
=====================================================================================

[](#jad-jsonapiorg-implementation-in-slim-4-framework)

Simplest way to have JSON:API endpoint in your Slim project

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

[](#table-of-contents)

- [Install](#install)
- [Usage](#usage)

Install
-------

[](#install)

Via Composer

```
$ composer require benycode/slim-jad-middleware
```

Requires Slim 4.

Usage
-----

[](#usage)

Use [DI](https://www.slimframework.com/docs/v4/concepts/di.html) to inject the library Middleware classes:

```
use Psr\Container\ContainerInterface;
use Jad\Configure;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Doctrine\DBAL\Configuration as DoctrineConfiguration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use BenyCode\Slim\JadMiddleware\JsonApiMiddleware;

return [
    ......
  JsonApiMiddleware::class => function (ContainerInterface $container): JadApiMiddleware {

    $config = Configure::getInstance();

      $config
        ->setConfig('strict', true)
        ;

      return new JsonApiMiddleware(
        $container->get(EntityManager::class),
        $container->get(ResponseFactoryInterface::class),
        $config,
        '/api/json', // endpoint path, middleware will catch requests etc: /api/json/videos, /api/json/videos/1.....
      );
  },
  EntityManager::class => static function (ContainerInterface $container): EntityManager {
    /** @var array $settings */
    $settings = $container->get('settings');

    // Use the ArrayAdapter or the FilesystemAdapter depending on the value of the 'dev_mode' setting
    // You can substitute the FilesystemAdapter for any other cache you prefer from the symfony/cache library
    $cache = $settings['doctrine']['dev_mode'] ?
      DoctrineProvider::wrap(new ArrayAdapter()) :
      DoctrineProvider::wrap(new FilesystemAdapter(directory: $settings['doctrine']['cache_dir']));

      $config = Setup::createAttributeMetadataConfiguration(
        $settings['doctrine']['metadata_dirs'],
        $settings['doctrine']['dev_mode'],
        null,
        $cache
      );

      return EntityManager::create($settings['db'], $config);
  },
];
```

add a **Middlewares** to route globaly:

```
use BenyCode\Slim\JadMiddleware\JsonApiMiddleware;

$app
  ...
  ->add(JsonApiMiddleware::class)
  ;
  ...
```

Doctrine config:

```
$settings['db'] = [
    'driver' => 'pdo_mysql',
    'host' => 'localhost',
    'dbname' => 'test',
    'user' => 'root',
    'password' => '',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'driverOptions' => [
        // Turn off persistent connections
        PDO::ATTR_PERSISTENT => false,
        // Enable exceptions
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        // Emulate prepared statements
        PDO::ATTR_EMULATE_PREPARES => true,
        // Set default fetch mode to array
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        // Set character set
        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'
    ],
];

$settings['doctrine'] = [
	// Enables or disables Doctrine metadata caching
	// for either performance or convenience during development.
	'dev_mode' => true,

	// Path where Doctrine will cache the processed metadata
	// when 'dev_mode' is false.
	'cache_dir' => APP_ROOT . '/../var/doctrine',

	// List of paths where Doctrine will search for metadata.
	// Metadata can be either YML/XML files or PHP classes annotated
	// with comments or PHP8 attributes.
	'metadata_dirs' => [APP_ROOT . '/../src/Domain'],

	'migrations' => [
		'migrations_paths' => [
			'App\\Doctrine\\Migration' => dirname(__DIR__) . '/resources/doctrine/migrations',
		],
		'custom_template' => dirname(__DIR__) . '/resources/doctrine/doctrine_migrations_class.php.tpl',
    ],
];
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Total

3

Last Release

1293d ago

### Community

Maintainers

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

---

Top Contributors

[![benycode](https://avatars.githubusercontent.com/u/39025147?v=4)](https://github.com/benycode "benycode (11 commits)")

---

Tags

jsonmiddlewareapiframeworkslim

### Embed Badge

![Health badge](/badges/benycode-slim-jad-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/benycode-slim-jad-middleware/health.svg)](https://phpackages.com/packages/benycode-slim-jad-middleware)
```

###  Alternatives

[slim/csrf

Slim Framework 4 CSRF protection PSR-15 middleware

3512.1M92](/packages/slim-csrf)[lanin/laravel-api-debugger

Easily debug your JSON API.

2311.8M](/packages/lanin-laravel-api-debugger)[gotzmann/comet

Modern PHP framework for building blazing fast REST APIs and microservices

68816.2k1](/packages/gotzmann-comet)[davidepastore/slim-validation

A slim middleware for validation based on Respect/Validation

171223.7k3](/packages/davidepastore-slim-validation)[davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

338.9k1](/packages/davidepastore-slim-config)[davidepastore/slim-restrict-route

A Slim middleware to restrict ip addresses that will access to your routes

2220.6k1](/packages/davidepastore-slim-restrict-route)

PHPackages © 2026

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