A simple class that returns a formatted json response
composer require mikes/json-response
<?php
require __DIR__ . "/vendor/autoload.php";
use mikesjsonresponse\ResponseClass\JsonResponse;
$student = array(
'name' => 'John Smith',
'course' => 'Maths',
'level' => '101',
'collections' => ['books' => 'Intro to UML', 'music' => 'rap']
);
new JsonResponse('unauthorized', '', $student);
- success or ok - 200 http status
- unauthorizsed - 401 http status
- exception - 500 http status
string - the return message, leave empty if not available
array - an array of data