deralia / json-api
JsonAPI standard implementation
1.0.0
2021-05-21 16:50 UTC
Requires
- php: >=7.1
- ext-json: *
- guzzlehttp/psr7: ~1.2
- psr/cache: ^1.0
- psr/http-message: ~1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- guzzlehttp/guzzle: ~6.0
- jms/serializer: ~1.4
- phpunit/phpunit: ^8.0
- symfony/config: ^5.0
- symfony/event-dispatcher: ^5.0
- symfony/property-access: ^5.0
- symfony/routing: ^5.0
- symfony/yaml: ^5.0
Suggests
- guzzlehttp/guzzle: Guzzle is a HTTP-client supported by JsonApi HTTP Client
This package is auto-updated.
Last update: 2024-04-21 23:54:34 UTC
README
This project is an updated Fork of the
mikemirten/json-api
library.
Credits for the code base to the original author.
This repository contains PHP-implementation of the JsonAPI standard.
An integration with the Symfony Framework can be found inside of JsonApi-Bundle repository.
Install
Through composer:
composer require deralia/json-api
How to use (original Wiki)
Overview
Code example:
use Deralia\Component\JsonApi\Document\ResourceObject; use Deralia\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..." } } }