PHPackages                             adt/api-json-router - 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. adt/api-json-router

ActiveLibrary[API Development](/categories/api)

adt/api-json-router
===================

RESTful Router for Nette with Json schema specification and verification

v3.0(3mo ago)025.1k↓43.3%1MITPHPPHP &gt;=8.0

Since Mar 19Pushed 3mo ago12 watchersCompare

[ Source](https://github.com/AppsDevTeam/ApiJsonRouter)[ Packagist](https://packagist.org/packages/adt/api-json-router)[ RSS](/packages/adt-api-json-router/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (18)Used By (0)

ApiJsonRouter
=============

[](#apijsonrouter)

Creates a route that expects Json in request body, checks this body against Json schema supplied to the route and passes top level parameters to actions.

ApiJsonRouter extends [Contributte api-router](https://github.com/contributte/api-router) thus see the documentation for full routes definition.

[Opis JSON Schema](https://github.com/opis/json-schema) is used for full Json Schema standard validation.

Standard "draft-2020-12" is used for validation as default.

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

[](#installation)

```
composer require adt/api-json-router
```

Example
-------

[](#example)

### Router

[](#router)

```
final class RouterFactory
{
    // Prepare your route specification
    public static function getApiRouteSpecification(): array
    {
		return [
			'/api/devices>POST' => [
				'path' => '/api/devices//request',
				'presenter' => 'DeviceRequest',
				'method' => 'POST',
				'action' => 'create',
				'parameters' => [
					'uuid' => ['type' => 'string', 'requirement' => '.+'],
				],
				'body' => [
					'type' => 'object',
					'properties' => [
						'type' => ['type' => 'string'],
					],
					'required' => ['type']
				],
				'title' => 'Create a request',
				'description' => 'Create a request for a specific device.',
		    ]
	    ];
    }

    // Create API router
    public static function createRouter(): \ADT\ApiJsonRouter\ApiRouteList
    {
        $apiRouter = new \ADT\ApiJsonRouter\ApiRouteList('Api');
        $apiRouter->addRoutesBySpecification(self::getApiRouteSpecification());
        return $apiRouter;
    }
}
```

### DeviceRequest presenter

[](#devicerequest-presenter)

```
class DeviceRequestPresenter extends Presenter
{
    public function actionCreate(string $uuid, string $_type)
    {
        // Check if you have access to a specific device
        if ($this->deviceQuery->create()->byUuid($uuid)) {
            $this->sendJsonError(404);
        }

        // Create a device request
        $deviceRequest = new DeviceRequest($device, $_type)
        $this->em->persist();
        $this->em->flush();

        // Send a response
        $this->sendJson(['uuid' => $deviceRequest->getUuid(), 'type' => $device->getType()]);
    }
}
```

### Docs presenter

[](#docs-presenter)

```
class DocsPresenter extends Presenter
{
	public function actionDefault()
	{
		// Generate API documentation in Markdown format
		$apiDocumentation = new ADT\ApiJsonRouter\ApiDocumentation('API Docs', RouterFactory::getApiRouteSpecification());
		$markdownApiDocumentation = $apiDocumentation->getDocumentation();

		// Generate API documentation in HTML format
		// e.g. you can use https://github.com/erusev/parsedown
		die((new \Parsedown())->text($markdownApiDocumentation));
	}
}
```

### Error presenter

[](#error-presenter)

```
class ErrorPresenter extends Presenter
{
	public function renderDefault(Exception $exception)
	{
		if ($exception instanceof ApiException) {
		    $this->sendJsonError($exception->getCode(), $exception->getMessage());
		}

		Debugger::log($exception, ILogger::EXCEPTION);

		$this->sendJsonError(500, 'There was an error processing your request. Please try again later.');
	}
}
```

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance81

Actively maintained with recent releases

Popularity28

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 74.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 ~137 days

Recently: every ~194 days

Total

14

Last Release

101d ago

Major Versions

v1.6 → v2.02023-05-25

v2.4 → v3.02026-02-06

PHP version history (2 changes)v1.0PHP &gt;= 7.1.0

v2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ab62e3b1b51d124387f69d423b6de47d0006c75007b97f530ee87397291730e?d=identicon)[thorewi](/maintainers/thorewi)

---

Top Contributors

[![thorewi](https://avatars.githubusercontent.com/u/605858?v=4)](https://github.com/thorewi "thorewi (26 commits)")[![NoxZet](https://avatars.githubusercontent.com/u/23127344?v=4)](https://github.com/NoxZet "NoxZet (4 commits)")[![conflictboy](https://avatars.githubusercontent.com/u/17651244?v=4)](https://github.com/conflictboy "conflictboy (3 commits)")[![michallohnisky](https://avatars.githubusercontent.com/u/4747059?v=4)](https://github.com/michallohnisky "michallohnisky (2 commits)")

###  Code Quality

TestsCodeception

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/adt-api-json-router/health.svg)

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

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23914.2M16](/packages/hubspot-api-client)[pristas-peter/wp-graphql-gutenberg

Query gutenberg blocks with wp-graphql

310109.7k1](/packages/pristas-peter-wp-graphql-gutenberg)[uma/json-rpc

a JSON-RPC 2.0 server

3756.6k2](/packages/uma-json-rpc)

PHPackages © 2026

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