mikemirten / json-api
JsonAPI standard implementation
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 6 788
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: >=7.0
- guzzlehttp/psr7: ~1.2
- psr/cache: ^1.0
- psr/http-message: ~1.0
Requires (Dev)
- guzzlehttp/guzzle: ~6.0
- jms/serializer: ~1.4
- phpunit/phpunit: ~6.0
- symfony/config: ^3.0
- symfony/event-dispatcher: ~3.0
- symfony/property-access: ~3.0
- symfony/routing: ~3.0
- symfony/yaml: ^3.0
Suggests
- guzzlehttp/guzzle: Guzzle is a HTTP-client supported by JsonApi HTTP Client
This package is not auto-updated.
Last update: 2023-09-30 14:54:46 UTC
README
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
Overview
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..." } } }