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

ActiveLibrary[API Development](/categories/api)

geodpto/json-api
================

Framework agnostic JSON API (jsonapi.org) implementation. This is a maintained fork of neomerx/json-api.

v0.2.0(4y ago)07Apache-2.0PHPPHP ^8.0

Since Mar 8Pushed 4y ago1 watchersCompare

[ Source](https://github.com/GeoDpto/json-api)[ Packagist](https://packagist.org/packages/geodpto/json-api)[ Docs](https://github.com/GeoDpto/json-api)[ RSS](/packages/geodpto-json-api/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/9c78128441ef4721739d0bc55197f640172e2587a8333befe9a7d46d57fc6eed/68747470733a2f2f7472617669732d63692e6f72672f6e656f6d6572782f6a736f6e2d6170692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/neomerx/json-api)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/f66943c28ae10dcbcf02fb187d53b86f200c1bb19cbbf15806d80e4db70cf4e5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e656f6d6572782f6a736f6e2d6170692f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/neomerx/json-api/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/3d13d1002763e74d3fe83c173d92483015004d75b0ed52656f27d2e4cdccf229/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e656f6d6572782f6a736f6e2d6170692f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/neomerx/json-api/?branch=master)[![License](https://camo.githubusercontent.com/749395c4ce36fed2206bf63c3d803b4a83d9592114908ace3dea4d292100f606/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e656f6d6572782f6a736f6e2d6170692e737667)](https://packagist.org/packages/neomerx/json-api)

Header
------

[](#header)

This is a maintained fork of [neomerx/json-api](https://github.com/neomerx/json-api).

Description
-----------

[](#description)

[![JSON API logo](https://camo.githubusercontent.com/5a13bdb171c3e1f6fc251a70f751b4b1957b598dd08dcf265ca7867fc1fef4b1/687474703a2f2f6a736f6e6170692e6f72672f696d616765732f6a736f6e6170692e706e67 "JSON API")](http://jsonapi.org/)

A good API is one of most effective ways to improve the experience for your clients. Standardized approaches for data formats and communication protocols increase productivity and make integration between applications smooth.

This framework agnostic package implements [JSON API](http://jsonapi.org/) specification **version v1.1** and helps focusing on core application functionality rather than on protocol implementation. It supports document structure, errors, data fetching as described in [JSON API Format](http://jsonapi.org/format/) and covers parsing and checking HTTP request parameters and headers. For instance it helps to correctly respond with `Unsupported Media Type` (HTTP code 415) and `Not Acceptable` (HTTP code 406) to invalid requests. You don't need to manually validate all input parameters on every request. You can configure what parameters are supported by your services and this package will check incoming requests automatically. It greatly simplifies API development and fully support specification. In particular

- Resource attributes and relationships
- Polymorphic resource data and relationships
- Compound documents with inclusion of related resources (circular resource references supported)
- Meta information for document, resources, errors, relationship and link objects
- Profiles
- Parsing HTTP `Accept` and `Content-Type` headers in accordance with [RFC 7231](https://tools.ietf.org/html/rfc7231)
- Parsing HTTP query parameters (e.g. pagination, sorting and etc)
- Sparse fieldsets and customized included paths
- Errors

High code quality and **100% test coverage** with **150+ tests**. Production ready.

**To find out more, please check out the [Wiki](https://github.com/neomerx/json-api/wiki) and [Sample App](/sample)**.

> “I'm loving how easy it makes it to quickly implement an api” – *Jeremy Cloutier*

Full-stack Integration
----------------------

[](#full-stack-integration)

This package is framework agnostic and if you are looking for practical usage sample you might be interested in Quick start JSON API server application [Limoncello App](https://github.com/limoncello-php/app).

The server supports

- CRUD operations for a few sample data models and Users.
- Cross-origin requests (CORS) to API server.
- Authentication (Bearer token) and authorizations for CRUD operations.
- Support for such JSON API features as resource inclusion, pagination and etc.

[![Demo app screen-shot](https://raw.githubusercontent.com/limoncello-php/app/master/server/resources/img/screen-shot.png "Limoncello App")](https://github.com/limoncello-php/app)

Sample usage
------------

[](#sample-usage)

Assuming you've got an `$author` of type `\Author` you can encode it to JSON API as simple as this

```
$encoder = Encoder::instance([
        Author::class => AuthorSchema::class,
    ])
    ->withUrlPrefix('http://example.com/api/v1')
    ->withEncodeOptions(JSON_PRETTY_PRINT);

echo $encoder->encodeData($author) . PHP_EOL;
```

will output

```
{
    "data" : {
        "type"       : "people",
        "id"         : "123",
        "attributes" : {
            "first-name": "John",
            "last-name": "Doe"
        },
        "relationships" : {
            "comments" : {
                "links": {
                    "related" : "http://example.com/api/v1/people/123/comments"
                }
            }
        },
        "links" : {
            "self" : "http://example.com/api/v1/people/123"
        }
    }
}
```

The `AuthorSchema` provides information about resource's attributes and might look like

```
class AuthorSchema extends BaseSchema
{
    public function getType(): string
    {
        return 'people';
    }

    public function getId($author): ?string
    {
        return $author->authorId;
    }

    public function getAttributes($author, ContextInterface $context): iterable
    {
        return [
            'first-name' => $author->firstName,
            'last-name'  => $author->lastName,
        ];
    }

    public function getRelationships($author, ContextInterface $context): iterable
    {
        return [
            'comments' => [
                self::RELATIONSHIP_LINKS_SELF    => false,
                self::RELATIONSHIP_LINKS_RELATED => true,

                // Data include supported as well as other cool features
                // self::RELATIONSHIP_DATA => $author->comments,
            ],
        ];
    }
}
```

Parameter `http://example.com/api/v1` is a URL prefix that will be applied to all encoded links unless they have a flag set telling not to add any prefixes.

Parameter `JSON_PRETTY_PRINT` is a PHP predefined [JSON constant](http://php.net/manual/en/json.constants.php).

A sample program with encoding of multiple, nested, filtered objects and more is [here](sample).

**For more advanced usage please check out the [Wiki](https://github.com/neomerx/json-api/wiki)**.

Versions
--------

[](#versions)

Current version is 4.x (PHP 7.1+) for older PHP (PHP 5.5 - 7.0, HHVM) please use version 1.x.

Questions?
----------

[](#questions)

Do not hesitate to check [issues](https://github.com/neomerx/json-api/issues) or post a new one.

Need help?
----------

[](#need-help)

Are you planning to add JSON API and need help? We'd love to talk to you .

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

[](#contributing)

If you have spotted any specification changes that are not reflected in this package please post an [issue](https://github.com/neomerx/json-api/issues). Pull requests for documentation and code improvements are welcome.

There are 2 ways to send pull requests

- small pull requests should be sent to `develop` branch as **1 commit**
- for bigger pull requests (e.g. new features) it's recommended to create an `issue` requesting a new branch for that feature. When a new branch named `feature/issueXX` is created (where `XX` is the issue number) you should post pull requests to this branch. When the feature is completed the branch will be squashed and merged to `develop` and then to `master` branches.

License
-------

[](#license)

Apache License (Version 2.0). Please see [License File](LICENSE) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

2

Last Release

1522d ago

PHP version history (2 changes)v0.1.0PHP &gt;=7.1.0

v0.2.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b624ebb6e448640778916a84920264315a6efc295a0b36bb9bb557cec2bb380?d=identicon)[GeoDpto](/maintainers/GeoDpto)

---

Top Contributors

[![GeoDpto](https://avatars.githubusercontent.com/u/41121407?v=4)](https://github.com/GeoDpto "GeoDpto (8 commits)")

---

Tags

jsonapijsonapiJSON-APIjsonapi.org

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[neomerx/json-api

Framework agnostic JSON API (jsonapi.org) implementation

7373.6M27](/packages/neomerx-json-api)[cloudcreativity/laravel-json-api

JSON API (jsonapi.org) support for Laravel applications.

7881.1M5](/packages/cloudcreativity-laravel-json-api)[cloudcreativity/json-api-testing

PHPUnit test helpers to check JSON API documents.

141.6M3](/packages/cloudcreativity-json-api-testing)[alsvanzelf/jsonapi

Human-friendly library to implement JSON:API without needing to know the specification.

54150.0k5](/packages/alsvanzelf-jsonapi)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.0k](/packages/nilportugues-jsonapi-bundle)[laravel-json-api/eloquent

Serialize Eloquent models as JSON:API resources.

121.4M4](/packages/laravel-json-api-eloquent)

PHPackages © 2026

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