foothing/uniform-json-responses

A PHP trait to uniform http responses.

0.1.0 2017-06-19 05:21 UTC

This package is auto-updated.

Last update: 2024-11-22 23:57:43 UTC


README

This is a tiny package meant to be used within Laravel. It defines a trait that can be used to wrap and uniform JSON responses to a reusable format.

Install

composer require foothing/uniform-json-responses

Usage

Simply add the trait to your Controller and have your controller actions to return content via the trait success or fail api.

class FooController {

	use WrapsResponses;

	public function getIndex() {
		// Do stuff
		return $this->success($dataToBeJSONed, 'Hey! It works.');
	}

	public function putIndex() {
		// Do more bad stuff.
		return $this->fail("Doh, this is broken", 500);
	}

}

The messages you can pass along with success and fail will be included in a X-Status-Message header.