PHPackages                             tobyz/json-api-server - 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. [Database &amp; ORM](/categories/database)
4. /
5. tobyz/json-api-server

ActiveLibrary[Database &amp; ORM](/categories/database)

tobyz/json-api-server
=====================

A fully automated JSON:API server implementation in PHP.

v0.2.1(2y ago)7013.8k↑201.3%22[1 issues](https://github.com/tobyzerner/json-api-server/issues)3MITPHPPHP &gt;=7.3CI failing

Since Jan 16Pushed 2mo ago5 watchersCompare

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

READMEChangelog (10)Dependencies (9)Versions (24)Used By (3)

json-api-server
===============

[](#json-api-server)

[![Pre Release](https://camo.githubusercontent.com/87e947dad8c6f14088b8d7ee986218fa23ef216ed3f10cfaeeea0390fc0e174c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f746f62797a2f6a736f6e2d6170692d7365727665722e7376673f7374796c653d666c6174)](https://github.com/tobyzerner/json-api-server/releases)[![License](https://camo.githubusercontent.com/348659f9d37159b3b1a68ab6cc596fc776419a81fe9217696245d7e2da1888f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f62797a2f6a736f6e2d6170692d7365727665722e7376673f7374796c653d666c6174)](https://packagist.org/packages/tobyz/json-api-server)

json-api-server is a [JSON:API](http://jsonapi.org) server implementation in PHP.

It allows you to build a feature-rich API by defining resource schema and connecting it to your application's database layer.

Based on your schema definition, the package will serve a complete API that conforms to the [JSON:API specification](https://jsonapi.org/format/), including support for:

- **Showing** individual resources (`GET /articles/1`)
- **Listing** resource collections (`GET /articles`)
- **Sorting**, **filtering**, **pagination**, and **sparse fieldsets**
- **Compound documents** with inclusion of related resources
- **Creating** resources (`POST /articles`)
- **Updating** resources (`PATCH /articles/1`)
- **Deleting** resources (`DELETE /articles/1`)
- **Content negotiation**
- **Error handling**
- **Localization** for customizing error messages
- **Extensions** including Atomic Operations
- **Generating OpenAPI definitions**

Documentation
-------------

[](#documentation)

[Read the documentation](https://tobyzerner.github.io/json-api-server)

Example
-------

[](#example)

The following example uses an Eloquent model in a Laravel application. However, json-api-server can be used with any framework that can deal in PSR-7 Requests and Responses. Custom behavior can be implemented to support other ORMs and data persistence layers.

```
use App\Models\User;
use Tobyz\JsonApiServer\Laravel;
use Tobyz\JsonApiServer\Laravel\EloquentResource;
use Tobyz\JsonApiServer\Laravel\Filter;
use Tobyz\JsonApiServer\Endpoint;
use Tobyz\JsonApiServer\Schema\Field;
use Tobyz\JsonApiServer\Schema\Type;
use Tobyz\JsonApiServer\JsonApi;

class UsersResource extends EloquentResource
{
    public function type(): string
    {
        return 'users';
    }

    public function newModel(Context $context): object
    {
        return new User();
    }

    public function endpoints(): array
    {
        return [
            Endpoint\Show::make(),
            Endpoint\Index::make()->paginate(),
            Endpoint\Create::make()->visible(Laravel\can('create')),
            Endpoint\Update::make()->visible(Laravel\can('update')),
            Endpoint\Delete::make()->visible(Laravel\can('delete')),
        ];
    }

    public function fields(): array
    {
        return [
            Field\Attribute::make('name')
                ->type(Type\Str::make())
                ->writable()
                ->required(),

            Field\ToOne::make('address')->includable(),

            Field\ToMany::make('friends')
                ->type('users')
                ->includable(),
        ];
    }

    public function filters(): array
    {
        return [Filter\Where::make('id'), Filter\Where::make('name')];
    }
}

$api = new JsonApi();

$api->resource(new UsersResource());

/** @var Psr\Http\Message\ServerRequestInterface $request */
/** @var Psr\Http\Message\ResponseInterface $response */
try {
    $response = $api->handle($request);
} catch (Throwable $e) {
    $response = $api->error($e);
}
```

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance58

Moderate activity, may be stable

Popularity43

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.1% 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 ~100 days

Recently: every ~188 days

Total

19

Last Release

138d ago

Major Versions

v0.2.0 → v1.0.0-alpha.12023-06-21

0.2.x-dev → v1.0.0-alpha.22023-08-19

PHP version history (3 changes)v0.1.0-beta.1PHP &gt;=7.1

v1.0.0-alpha.1PHP &gt;=8.1

v0.2.1PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f8dd03c68eabcc2e3aa051d19d48ef96f1f5ae0af424918b8053dea93047703?d=identicon)[tobyzerner](/maintainers/tobyzerner)

---

Top Contributors

[![tobyzerner](https://avatars.githubusercontent.com/u/128862?v=4)](https://github.com/tobyzerner "tobyzerner (336 commits)")[![SychO9](https://avatars.githubusercontent.com/u/20267363?v=4)](https://github.com/SychO9 "SychO9 (9 commits)")[![bertramakers](https://avatars.githubusercontent.com/u/959026?v=4)](https://github.com/bertramakers "bertramakers (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![asispts](https://avatars.githubusercontent.com/u/79239132?v=4)](https://github.com/asispts "asispts (3 commits)")[![davwheat](https://avatars.githubusercontent.com/u/7406822?v=4)](https://github.com/davwheat "davwheat (1 commits)")[![basemaster](https://avatars.githubusercontent.com/u/4114790?v=4)](https://github.com/basemaster "basemaster (1 commits)")[![acorncom](https://avatars.githubusercontent.com/u/802505?v=4)](https://github.com/acorncom "acorncom (1 commits)")[![smtlab](https://avatars.githubusercontent.com/u/3519592?v=4)](https://github.com/smtlab "smtlab (1 commits)")

---

Tags

eloquentjson-apiphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tobyz-json-api-server/health.svg)

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

###  Alternatives

[bref/bref

Bref is a framework to write and deploy serverless PHP applications on AWS Lambda.

3.4k9.6M55](/packages/bref-bref)[kreait/firebase-php

Firebase Admin SDK

2.4k39.7M72](/packages/kreait-firebase-php)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.4k84.1k1](/packages/getgrav-grav)[mevdschee/php-crud-api

Single file PHP script that adds a REST API to a SQL database.

3.7k63.8k9](/packages/mevdschee-php-crud-api)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

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