|Last Updated|| ||Ratings|| ||Unique User Downloads|| ||Download Rankings|
|2019-09-18 (1 month ago) ||Not enough user ratings||Total: 172 This week: 2||All time: 8,537 This week: 189|
This class can generate a HTTP request response in JSON format.
It can take an a variable value as parameter and generates a JSON encoded string from that value to serve it as response for the current request.
The class can also take the string for the request status value and serves the respective HTTP response header being 200 for ok, 401 for unauthorized and 500 for exception.
|HTTP requests need to have a response that uses status codes to let browsers or HTTP clients know if a request was handled successfully or some other outcome has happened.
HTTP status codes are numbers, which are usually not human friendly because they do not mean anything unless the developer looks up or remembers their meaning of all the HTTP status codes that you use in an application.
This class provides a more human friendly solution to issue HTTP status codes that consists in passing just the text message of the HTTP status, so the class automatically determines the HTTP status code numbers.
A simple class that returns a properly formatted json response with HTTP status
composer require devscreencast/json-response
require_once __DIR__ ."/vendor/autoload.php";
$student = array(
'name' => 'John Doe',
'course' => 'Software Engineering',
'level' => '200',
'collections' => ['books' => 'Intro to UML', 'music' => 'rap']
new JsonResponse('ok', '', $student);
Param 1 (Required)
- success or ok - 200 http status
- unauthorized - 401 http status
- exception - 500 http status (internal server error)
Param 2 (Optional)
string - the return message, use empty quote if not available
Param 3 (Optional)
Array - Array of Data
||Applications that use this package
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.