JsonAPI standard implementation

v0.34 2018-01-08 23:37 UTC


Build Status Code Coverage Scrutinizer Code Quality

This repository contains PHP-implementation of the JsonAPI standard.

An integration with the Symfony Framework can be found inside of JsonApi-Bundle repository.

How to install

Through composer:

composer require mikemirten/json-api

How to use


use Mikemirten\Component\JsonApi\Document\ResourceObject;
use Mikemirten\Component\JsonApi\Document\SingleResourceDocument;

// ...

$post = $postRepository->findById($id);

$resource = new ResourceObject($id, 'Post', [
    'title' => $post->getTitle(),
    'body'  => $post->getBody()

$document = new SingleResourceDocument($resource);

echo json_encode($document->toArray());

Response body:

    "data": {
        "id": "1",
        "type": "Post",
        "attributes": {
            "title": "Lorem Ipsum",
            "body": "Lorem ipsum dolor sit amet, lobortis urna sed imperdiet..."