Skip to content

Instantly share code, notes, and snippets.

View RichardStyles's full-sized avatar

Richard Styles RichardStyles

View GitHub Profile
@RichardStyles
RichardStyles / JsonResponse.php
Last active May 26, 2016 18:31
Middleware for PHP Slim framework 3.x to output JSON responses with the correct header. Probably a better way to do this then just simply interrogating the response body, but for a initial test sufficient for my needs.
<?php
/**
* Middleware to set correct header for JSON output.
* Very basic initial version, simply checks the body of the response to see if it is valid JSON.
* If response is not JSON then continues with default settings.
* If response is JSON then header is updated.
*
* @author Richard Styles
*/
namespace App\Middleware;