PHPackages                             docnet/php-japi - 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. docnet/php-japi

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

docnet/php-japi
===============

Simple framework for building HTTP JSON APIs in PHP. 2.

v2.0.0(10y ago)615.9k↓22.7%14[3 issues](https://github.com/DocnetUK/php-japi/issues)Apache-2.0PHPPHP &gt;=5.4.0

Since Jun 23Pushed 7mo ago10 watchersCompare

[ Source](https://github.com/DocnetUK/php-japi)[ Packagist](https://packagist.org/packages/docnet/php-japi)[ Docs](https://github.com/DocnetUK/php-japi)[ RSS](/packages/docnet-php-japi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (0)

[![Build Status](https://camo.githubusercontent.com/c168b81953fff19b22f25dd451cfdb20918cfb9ec4c8d8dbfa85f13b7c39b0ff/68747470733a2f2f6170692e7472617669732d63692e6f72672f446f636e6574554b2f7068702d6a6170692e7376673f6272616e63683d322e30)](https://travis-ci.org/DocnetUK/php-japi)[![Coverage Status](https://camo.githubusercontent.com/fad5ee030e0eb30764b3e517a7a0ebe736eede3d2e3058633e860f1ed7ed0bd4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f446f636e6574554b2f7068702d6a6170692f62616467652e7376673f6272616e63683d322e30)](https://coveralls.io/r/DocnetUK/php-japi)

PHP JSON API Library
====================

[](#php-json-api-library)

Version 2 of our library for building HTTP JSON APIs in PHP.

Some major changes in version 2

- Adopt better code practices, allowing for Dependency Injection
- Adopt our new "Single Responsibility Controller" approach
- Decouple Router from JAPI container
- Use PSR logging
- Adopt PHP 5.4 minimum version

As we expand our Service Orientated Architecture (SOA) at Docnet, we're using this more and more - so I hope it's useful to someone else ;)

Intended to use HTTP status codes wherever possible for passing success/failure etc. back to the client.

Single Responsibility Controller
--------------------------------

[](#single-responsibility-controller)

We've adopted a new (for us) take on routing and controller complexity in 2.0. As such, where previously, you might have had multiple actions (methods) on the same class like this:

- `BasketController::fetchDetailAction()`
- `BasketController::addAction()`
- `BasketController::removeAction()`
- `BasketController::emptyAction()`

Now this would be 4 name-spaced classes, like this

- `Basket\FetchDetail`
- `Basket\Add`
- `Basket\Remove`
- `Basket\Empty`

This allows for

- Greater code modularity
- Smaller classes
- Much easier Dependency Injection via `__construct()` as each "action" is it's own class.

You can still share common code via extension/composition - whatever takes your fancy!

JAPI will call the `dispatch()` method on your controller.

### SOLID Routing

[](#solid-routing)

The bundled router will accept any depth of controller namespace, like this

- `/one` =&gt; `One`
- `/one/two` =&gt; `One\Two`
- `/one/two/three` =&gt; `One\Two\Three`

When you construct the Router, you can give it a "root" namespace, like this:

```
$router = new \Docnet\JAPI\SolidRouter('\\Docnet\\App\\Controller\\');
```

Which results in this routing:

- `/one/two` =&gt; `\Docnet\App\Controller\One\Two`

### Static Routes

[](#static-routes)

If you have some static routes you want to set up, that's no problem - they also bypass the routing regex code and so make calls very slightly faster.

Add a single custom route

```
$router = new \Docnet\JAPI\SolidRouter();
$router->addRoute('/hello', '\\Some\\Controller');
```

Or set a load of them

```
$router = new \Docnet\JAPI\SolidRouter();
$router->setRoutes([
    '/hello' => '\\Some\\Controller',
    '/world' => '\\Other\\Controller'
]);
```

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

[](#installation)

Here's the require line for Composer users (during 2-series development)...

`"docnet/php-japi": "2.0.*@dev"`

...or just download and use the src folder.

Bootstrapping
-------------

[](#bootstrapping)

Assuming...

- You've got Apache/whatever set up to route all requests to this file
- An auto-loader is present (like the Composer example here) or you've included all files necessary

...then something like this is all the code you need in your `index.php`

```
(new \Docnet\JAPI())->bootstrap(function(){

    $obj_router = new \Docnet\JAPI\SolidRouter();
    $obj_router->route();

    $str_controller = $obj_router->getController();
    return new $str_controller();

});
```

See the examples folder for a working demo (api.php).

Coding Standards
----------------

[](#coding-standards)

Desired adherence to [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md). Uses [PSR-3](https://github.com/php-fig/log) logging.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~324 days

Recently: every ~342 days

Total

6

Last Release

2727d ago

Major Versions

v1.1.1 → v2.0.02015-10-27

PHP version history (2 changes)v1.1.0PHP &gt;=5.3.0

v2.0.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e2b28a219ee1eb3272465e6405928b762272593849b52ecfa5576b5119d9d5e?d=identicon)[Docnet](/maintainers/Docnet)

---

Top Contributors

[![craig-mcmahon](https://avatars.githubusercontent.com/u/5879594?v=4)](https://github.com/craig-mcmahon "craig-mcmahon (3 commits)")[![kabudu](https://avatars.githubusercontent.com/u/3732230?v=4)](https://github.com/kabudu "kabudu (1 commits)")[![mullikine](https://avatars.githubusercontent.com/u/1020987?v=4)](https://github.com/mullikine "mullikine (1 commits)")

---

Tags

httpjsonapidocnet

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/docnet-php-japi/health.svg)

```
[![Health](https://phpackages.com/badges/docnet-php-japi/health.svg)](https://phpackages.com/packages/docnet-php-japi)
```

###  Alternatives

[zircote/swagger-php

Generate interactive documentation for your RESTful API using PHP attributes (preferred) or PHPDoc annotations

5.3k132.9M468](/packages/zircote-swagger-php)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

59300.2k11](/packages/vinelab-http)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)[rap2hpoutre/jacky

Opinionated REST JSON HTTP API client for laravel

174.4k](/packages/rap2hpoutre-jacky)

PHPackages © 2026

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