A simple class that returns a propely formatted json response with HTTP status
composer require francscafe/json-response
<?php
/**
* Created by PhpStorm.
* User: fcromer
* Date: 9/6/18
* Time: 4:57 PM
*/
require_once __DIR__ ."/vendor/autoload.php";
use Francscafe\ResponseClass\JsonResponse;
$student = array(
'name' => 'John Doe',
'course' => 'Software Engineering',
'collections' => ['books' => 'Intro to UML', 'music' => 'rap']
);
new JsonResponse('ok', '', $student);
- success or ok - 200 http status
- unauthorized - 401 http status
- exception - 500 http status (internal server error)
string - the return message, use empty quote if not available
Array - Array of Data