tyler36/response-macro

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (1.1) of this package.

Standardizing JSON responses

Maintainers

👁 tyler36

Package info

github.com/tyler36/response-macro

Type:laravel-plugin

pkg:composer/tyler36/response-macro

Statistics

Installs: 23

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1 2018-07-20 06:03 UTC

Requires

  • php: >=7.0

Suggests

None

Provides

None

Conflicts

None

Replaces

None

Unknown License d24ad1f6b3c438e4d58a9818f2d0d5eae33aab18

responseservice-providerlaravel

This package is not auto-updated.

Last update: 2024-12-08 05:50:28 UTC


README

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

Installation

  • Install package
composer require tyler36/response-macro

Success

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

response()->success($data);

EG.

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

Returns HTTP status 200 with the following:

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

noContent

Returns empty content with a HTTP status code 402

response()->noContent()

Error

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

response()->error($message);

Eg.

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

Returns HTTP status 400 with the following:

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

Eg.

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

Returns HTTP status 403 with the following:

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