Download the PHP package earthling-interactive/laravel-jsonapi without Composer
On this page you can find all versions of the php package earthling-interactive/laravel-jsonapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-jsonapi
JSON API helpers for Laravel 5
Make it a breeze to create a jsonapi.org RC3 compliant API with Laravel 5.
Code forked from echo-it/laravel-jsonapi project by Ronni Egeriis Persson.
Installation
-
Add
earthling-interactive/laravel-jsonapi
to your composer.json dependency list - Run
composer update
.
Requirements
- PHP 5.4+
- Laravel 5
Using laravel-jsonapi
This library is made with the concept of exposing models in mind, as found in the RESTful API approach.
In few steps you can expose your models:
-
Create a route to direct the requests
In this example, we use a route for any OPTION requests, a generic route for interacting with resources, and another route for interacting with resource relationships:
-
Create your controller to handle the request
Your controller is responsible to handling input, instantiating a handler class and returning the response.
-
Create a handler for your model
A handler is responsible for exposing a single model.
In this example we have create a handler which supports the following requests:
- GET /users (ie. handleGet function)
- GET /users/[id] (ie. handleGet function)
- PATCH /users/[id] (ie. handlePatch function)
Requests are automatically routed to appropriate handle functions.
Note: Extend your models from EarthlingInteractive\JsonApi\Model
rather than Eloquent
to get the proper response for linked resources. In your model, you can define which relationships should be exposed:
Current features
According to jsonapi.org:
- Resource Representations as resource objects
- Resource Relationships
- Relationship URLs e.g. /users/[id]/links/friends
- Compound Documents
- Sorting
- Filtering (Note: Doesn't use FILTER keyword. An example: /users?name=Joe)
- Pagination
The features in the Handler class are each in their own function (eg. handlePaginationRequest, handleSortRequest, etc.), so you can easily override them with your own behaviour if desired.
Wishlist
- Resource URLs
- Updating Relationships
- Sparse Fieldsets
- Strict checking of application/vnd.api+json in content-type and Accept Headers
All versions of laravel-jsonapi with dependencies
illuminate/database Version 5.0.*
illuminate/http Version 5.0.*
illuminate/support Version 5.0.*
illuminate/pagination Version 5.0.*