Download the PHP package lassehaslev/api-response without Composer
On this page you can find all versions of the php package lassehaslev/api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lassehaslev/api-response
More information about lassehaslev/api-response
Files in lassehaslev/api-response
Package api-response
Short Description Helper class for giving JSON api response
License MIT
Informations about the package api-response
api-response
Helper class for giving JSON api response
Motivation
Its hard to allways write api response for everyting, and this package will make the job much easier.
This package and its base concept is greatly inspired by dingo/api. And uses most of the same transformer syntax as Fractal.
Install
I use this package mainly in my Laravel projects.
Run in your project folder
Usage
Responder
The Responder is where we call what items we want transformed to JsonResponse. This class need to implement the and will then make the object available. This will make it posible to use and . The first argument for both functions are the data to be transformed, the second argument is the transformer to transform the data. Read below for more information.
Transformer
The transformer is where we format the data to the api. All you have to do is to create a with the model you want to transformed. Then you return an with the data.
You can also have the transformer include more data. This can be useful when model has data. This is done by two different types and , but both types works the same way: Update the array of the type example: . Then you need to create a public function thats has name prefix . Example: .
Default includes
The default include will be included by default.
Available includes
The available include will only be included when url parameter are provided. Example
If you have multiple available includes you can include them by having url request like
License
MIT, dawg