Download the PHP package gridonic/json-response without Composer
On this page you can find all versions of the php package gridonic/json-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gridonic/json-response
More information about gridonic/json-response
Files in gridonic/json-response
Package json-response
Short Description Structures JSON responses for the JSend format
License MIT
Homepage http://gridonic.ch
Informations about the package json-response
JsonResponse
Provides simple classes for JSON responses that adhere to a standardized structure. Since JSON responses may have very different formats, this package supports the specific JSend format defined at http://labs.omniti.com/labs/jsend.
This package is an extension of the HttpFoundation\JsonResponse class from the Symfony package.
Install
The recommended way to install JsonResponse is through composer.
You can either add it as a depedency to your project using the command line:
$ composer require gridonic/json-response
or by adding it directly to your file:
Run these two commands to install it:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
Now you can add the autoloader, and you will have access to the library:
JsonResponse
We differentiate between two different types of Responses:
- SuccessJsonResponse
- ErrorJsonResponse
SuccessJsonResponse
Parameter | Type | Needed? | Default value | Description |
---|---|---|---|---|
$data |
mixed | optional | null | The response data |
$message |
string | optional | null | A success message |
$title |
string | optional | null | A success title |
$status |
integer | optional | 200 | The response status code |
$headers |
array | optional | array() | An array of response headers |
ErrorJsonResponse
Parameter | Type | Needed? | Default value | Description |
---|---|---|---|---|
$data |
mixed | optional | null | The response data |
$message |
string | required | The error message | |
$title |
string | optional | null | An error title |
$status |
integer | optional | 400 | The response status code |
$errorCode |
string | optional | null | An individual error code |
$errors |
array | optional | array() | An array of errors |
$headers |
array | optional | array() | An array of response headers |
JSend
Our Responses are based on the Model of JSend. You can find the documentation of JSend on the JSend website
Usage
SuccessJsonResponse
Use a Gridonic\JsonResponse\SuccessJsonResponse
to build a structured JSON Response.
Empty SuccessJsonResponse
SuccessJsonResponse with Content
SuccessJsonResponse
Use a Gridonic\JsonResponse\ErrorJsonResponse
to build a structured JSON Response.
ErrorJsonResponse with Message
ErrorJsonResponse with Content
Major & Minor Releases
1.1.0
New structure of the responses
1.0.0
Initial Release
Licence
The JsonResponse is licensed under the MIT license.