1. Go to this page and download the library: Download nickjbedford/json-response library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nickjbedford / json-response example snippets
$response = json_success();
$json = $response->toJSON();
$json = strval($response); // This calls $response->toJSON()
// Create a response with a payload
$personResponse = json_success([
'id' => 123,
'name' => 'John Citizen',
'dob' => '1985-01-01'
]);
$response = json_failure("Person not found.", "E_NOTFOUND");
$json = $response->toJSON();
$exception = new Exception("Database connection was lost.", "E_DBCONN");
$response = json_exception($exception, true); // true to