Skip to content

json-api-php/json-api

 
 

Repository files navigation

Implementation of JSON API in PHP 7

This library is an attempt to express business rules of JSON API specification in a set of PHP 7 classes.

A simple example to illustrate the general idea. This JSON representation from the documentation

{
    "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"
                }
            }
        }
    }
}

can be built with the following php code:

<?php
$articles = new ResourceObject('articles', '1');
$author = Relationship::fromLinkage(
    Linkage::fromSingleIdentifier(
        new ResourceIdentifier('people', '9')
    )
);
$author->setLink('self', '/articles/1/relationships/author');
$author->setLink('related', '/articles/1/author');
$articles->setRelationship('author', $author);
$articles->setAttribute('title', 'Rails is Omakase');
$doc = Document::fromResource($articles);
echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

Please refer to the tests for the full API documentation:

Installation

With composer: json-api-php/json-api.

Sponsor this project

Packages

No packages published

Contributors 9

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy