Stars: 184
Forks: 18
Pull Requests: 80
Issues: 32
Watchers: 9
Last Updated: 2022-07-27 01:11:02
Implementation of JSON API in PHP
License: MIT License
Languages: PHP
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:
<?php
use JsonApiPhp\JsonApi\Attribute;
use JsonApiPhp\JsonApi\DataDocument;
use JsonApiPhp\JsonApi\Link\RelatedLink;
use JsonApiPhp\JsonApi\Link\SelfLink;
use JsonApiPhp\JsonApi\ResourceIdentifier;
use JsonApiPhp\JsonApi\ResourceObject;
use JsonApiPhp\JsonApi\ToOne;
echo json_encode(
new DataDocument(
new ResourceObject(
'articles',
'1',
new Attribute('title', 'Rails is Omakase'),
new ToOne(
'author',
new ResourceIdentifier('author', '9'),
new SelfLink('/articles/1/relationships/author'),
new RelatedLink('/articles/1/author')
)
)
),
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
);
composer require json-api-php/json-api
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.