2017 © Pedro Peláez
 

library jsend4laravel

Simply adds macros to Laravel 4's Response class for JSend-formatting responses.

image

vena/jsend4laravel

Simply adds macros to Laravel 4's Response class for JSend-formatting responses.

  • Friday, July 11, 2014
  • by vena
  • Repository
  • 1 Watchers
  • 0 Stars
  • 28 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

JSend4Laravel

This is just a simple package to add a few macros to Laravel 4's Response class and extend its json method for JSend-formatted responses., (*1)

Installation

Load the package with composer

Add the package in the require key of your composer.json:, (*2)

"vena/jsend4laravel": "dev-master"

Update composer to grab the package:, (*3)

composer update

Add the service provider to the end of your providers array in app/config/app.php:, (*4)

'providers' => array(
    ...
    'Vena\JSend4Laravel\JSend4LaravelServiceProvider',
);

That's it, no further configuration is necessary., (*5)

Usage

All macros return a Response object, allowing you to override anything about the response you require. Default HTTP status codes are included and everything eventually goes through the Response::json() method to set the appropriate Content-Type header, but what you do with the Response object is up to you., (*6)

Response::jsend($data, $httpStatus, $headers)

Wrapper around Response::json(). The response will be sent as JSONP if a 'callback' value is specified in the request input., (*7)

It's not especially useful to call this by itself, as it will not format the data whatsoever. However, all other JSend4Laravel methods ultimate route through this, which then returns a jsonResponse., (*8)

  • $data: Data to include in the response, defaults to NULL.
  • $httpStatus: HTTP status code for the response, defaults to 200.
  • $headers: Response headers for the response. JSON responses are always sent with Content-Type: application/json

Returns: Response, (*9)

Response::jsendSuccess($data, $httpStatus, $headers)

Formats a JSend success response with the supplied data. All parameters are optional., (*10)

  • $data: Data to include in the response, defaults to NULL.
  • $httpStatus: HTTP status code for the response, defaults to 200.
  • $headers: Response headers for the response.

Returns: Response, (*11)

Response::jsendFail($data, $httpStatus, $headers)

Formats a JSend fail response. All parameters are optional., (*12)

  • $data: Data to include in the response, defaults to NULL.
  • $httpStatus: HTTP status code for the response, defaults to 400.
  • $headers: Response headers for the response.

Returns: Response, (*13)

Response::jsendError($message, $code, $data, $httpStatus, $headers)

Formats a JSend error response with the supplied data., (*14)

  • $message: Required. A meangingful, human-readable message explaining the error.

All other parameters are optional:, (*15)

  • $code: A numeric reference code for the error, if applicable.
  • $data: Additional error data to send with the request (stack traces, other debug info). Not included in response if set to NULL (default).
  • $httpStatus: HTTP status code for the response, defaults to 400.
  • $headers: Response headers for the response.

Returns: Response, (*16)

The Versions

11/07 2014

dev-master

9999999-dev https://github.com/vena/jsend4laravel

Simply adds macros to Laravel 4's Response class for JSend-formatting responses.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Daniel Vena

laravel jsend