Skip to content

Repository files navigation

JSON API spec implemented in PHP 7. Immutable

The goal of this library is to ensure strict validity of JSON API documents being produced.

JSON:

{
"data": {
"type": "articles",
"id": "1",
"attributes": {
"title": "Rails is Omakase"
},
"relationships": {
"author": {
"data": {
"type": "people",
"id": "9"
},
"links": {
"self": "/articles/1/relationships/author",
"related": "/articles/1/author"
}
}
}
}
}

PHP:

<?phpuseJsonApiPhp\JsonApi\Attribute;
useJsonApiPhp\JsonApi\DataDocument;
useJsonApiPhp\JsonApi\Link\RelatedLink;
useJsonApiPhp\JsonApi\Link\SelfLink;
useJsonApiPhp\JsonApi\ResourceIdentifier;
useJsonApiPhp\JsonApi\ResourceObject;
useJsonApiPhp\JsonApi\ToOne;
echojson_encode(
newDataDocument(
newResourceObject(
'articles',
'1',
newAttribute('title', 'Rails is Omakase'),
newToOne(
'author',
newResourceIdentifier('author', '9'),
newSelfLink('/articles/1/relationships/author'),
newRelatedLink('/articles/1/author')
)
)
),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);

Installation

composer require json-api-php/json-api

Documentation

First, take a look at the examples. All of them are runnable.

The library API and use-cases are expressed in a comprehensive suite of tests.

About

Implementation of JSON API in PHP

Topics

Resources

Contributing

Stars

184 stars

Watchers

8 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages