Skip to content

lemonphp/json-api

Repository files navigation

lemonphp/json-api

Build Status Coverage Status Code Climate Issue Count

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.

About

👍 A PHP7 implement of JSON API specification

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages