2017 © Pedro Peláez
 

laravel-plugin response-macro

Standardizing JSON responses

image

tyler36/response-macro

Standardizing JSON responses

  • Friday, July 20, 2018
  • by tyler36
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Introduction

These macros help to standardize api json response returns throughout the application. Inspired by Laravel Response Macros for APIs, (*1)

Installation

  • Install package
composer require tyler36/response-macro

Success

Returns payload ($data) with an optional HTTP status code ($statusCode) [Default: [HTTP status code 200], (*2)

response()->success($data);

EG., (*3)

response()->success(['earth' => 3, 'sun' => 'yellow'])

Returns HTTP status 200 with the following:, (*4)

{"errors":false,"data":{"earth":3,"sun":"yellow"}}

noContent

Returns empty content with a HTTP status code 402, (*5)

response()->noContent()

Error

Returns message ($message) content with an optional HTTP status code ($statusCode) [Default: HTTP status code 400], (*6)

response()->error($message);

Eg., (*7)

response()->error('There was an error.');

Returns HTTP status 400 with the following:, (*8)

{"errors":true,"message":"There was an error."}

Eg., (*9)

response()->error('Not authorized!', 403);

Returns HTTP status 403 with the following:, (*10)

{"errors":true,"message":"Not authorized!"}

The Versions

20/07 2018

dev-master

9999999-dev

Standardizing JSON responses

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

laravel response service-provider

20/07 2018

1.1

1.1.0.0

Standardizing JSON responses

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

laravel response service-provider

07/06 2018

1.0

1.0.0.0

Standardizing JSON responses

  Sources   Download

The Requires

  • php >=7.0

 

The Development Requires

laravel response service-provider