Download the PHP package echo-it/laravel-jsonapi without Composer
On this page you can find all versions of the php package echo-it/laravel-jsonapi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-jsonapi
!!! Project abandoned. See cloudcreativity/laravel-json-api for a great alternative.
JSON API helpers for Laravel 5
Make it a breeze to create a jsonapi.org compliant API with Laravel 5.
This library strives to be up to date with the latest JSON API updates—as the spec is still a work in progress. If you notice that something is missing, please contribute!
Installation
-
Add
echo-it/laravel-jsonapi
to your composer.json dependency list (version 2.0.0 at the minimum for laravel 5 support) - 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 generic route for all models and HTTP methods:
-
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)
- PUT /users/[id] (ie. handlePut function)
Requests are automatically routed to appropriate handle functions.
Note: Extend your models from
EchoIt\JsonApi\Model
rather thanEloquent
to get the proper response for linked resources.
Current features
According to jsonapi.org:
- Resource Representations as resource objects
- Resource Relationships
- Only through Inclusion of Linked Resources
- Compound Documents
- Sorting
- Filtering
- [Pagination] (http://jsonapi.org/format/#fetching-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
- Nested requests to fetch relations, e.g. /users/[id]/friends
- Resource URLs
- Requests for multiple individual resources, e.g.
/users/1,2,3
- Some kind of caching mechanism
All versions of laravel-jsonapi with dependencies
illuminate/http Version 5.1.*
illuminate/support Version 5.1.*
illuminate/pagination Version 5.1.*