Download the PHP package bigz/halapi without Composer
On this page you can find all versions of the php package bigz/halapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package halapi
Short Description A PHP library to support implementing representations for HAL, REST over JSON web services
License MIT
Informations about the package halapi
Hypertext Application Language for (REpresentational State Transfer) Application Programming Interfaces
Given some conventions, displaying the HAL representation of any entity becomes very easy.
HAL is a json presentation format of the HATEOAS constraint, which is meant to add relations between objects.
It's whole specification is available here http://stateless.co/hal_specification.html
The work is in progress to make it framework agnostic but actually relies on you using symfony/http-foundation, which will change in a close future to use psr6 (while providing a bridge) For the object manager, you are free to choose the one you like, although only doctrine orm has been implemented at the mement. Relation findings relies also a lot on doctrine's ClassMetadata interface, that we should maybe abstract (you can still use your own implementaion)
Usage
composer req bigz/halapi
Symfony bundle
https://github.com/BigZ/HalapiBundle
Full fledged example using symfony (a good starting point for your api)
https://github.com/BigZ/promote-api
Example
Resources
List
Pagination
A list will give you a paginated ressource, HAL formatted.
/entities?limit=2&page=2
Filtering
You can filter out results on specific fields.
/entities?filter[id]=5&filteroperator[id]=>
Available operators are >
, <
, >=
, <=
, =
, !=
Default operator is =
Sorting
You can sort the result by any property
/entities?sort=-created,title
Entity
Creating new entities
POST /entities
{ "entity": { "name": "eminem", "slug": "eminem", "bio": "rapper from detroit", "labels": [1, 2] } }
will return
{ "id": 2, "name": "eminem", "slug": "eminem", "bio": "rapper from detroit", "_links": { "self": "/artists/2", "labels": [ "/labels/1", "/labels/2" ] } }
PUT & PATCH works the same way
Embedding
By default, relations are not embeded. You can change this behaviour by specifiying wich embedeed entities you need.
/entities/1?embed[]=gigs&embed[]=labels
To allow an relation to be embedded, you must add an @Embeddable
Annotation to your entity property.
Roadmap to production readyness
- (MUST) Improve coverage
- (MUST) Implement sparse fieldset
- (MUST) Implement deep resource inclusion
- (SHOULD) support IN filter operator
- (SHOULD) Refactor using propertyinfo component
- (SHOULD) USE doctrine/reflection instead of doctrine/common
- (SHOULD) Be able to serialize to any other hateoas format. Not so easy with jms...
All versions of halapi with dependencies
doctrine/common Version ~2.0
doctrine/annotations Version ~1.0
jms/serializer Version ^1.0
symfony/options-resolver Version ^4.0
psr/http-message Version ^1.0