lemonphp / json-api
A PHP7 implement of JSON API specification
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/lemonphp/json-api
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ~6.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2025-10-08 09:50:49 UTC
README
A PHP7 implement of JSON API specification
Requirements
- php >= 7.0
Installation
$ composer require lemonphp/json-api
Usage
Example code:
<?php use Lemon\JsonApi\Document; use Lemon\JsonApi\Document\Resource\Relationship\Linkage; use Lemon\JsonApi\Document\Resource\Relationship\Relationship; use Lemon\JsonApi\Document\Resource\ResourceIdentifier; use Lemon\JsonApi\Document\Resource\ResourceObject; include_once 'vendor/autoload.php'; $author = Relationship::fromLinkage( Linkage::fromSingleIdentifier( new ResourceIdentifier('people', '9') ) ); $author->setLink('self', '/articles/1/relationships/author'); $author->setLink('related', '/articles/1/author'); $article = new ResourceObject('articles', '1'); $article->setAttribute('title', 'Hello word'); $article->setRelationship('author', $author); $doc = Document::fromResource($article); echo json_encode($doc, JSON_PRETTY_PRINT);
Output:
{
    "data": {
        "type": "articles",
        "id": "1",
        "attributes": {
            "title": "Hello word"
        },
        "relationships": {
            "author": {
                "data": {
                    "type": "people",
                    "id": "9"
                },
                "links": {
                    "self": "\/articles\/1\/relationships\/author",
                    "related": "\/articles\/1\/author"
                }
            }
        }
    }
}
Changelog
See all change logs in CHANGELOG.md
Contributing
All code contributions must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
Fork the project, create a feature branch, and send a pull request.
To ensure a consistent code base, you should make sure the code follows the PSR-2.
If you would like to help take a look at the list of issues.
License
This project is released under the MIT License.
Copyright © 2017 LemonPHP Team.