apsxj / json
JSON 1.0 Library for Web APIs
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
pkg:composer/apsxj/json
This package is auto-updated.
Last update: 2025-10-18 02:34:58 UTC
README
JSON 1.0 Library for Web APIs
This library was designed using the JSON:API v1.0 STABLE specification.
Getting Started
- Add the following to your
composer.jsonfile:
"require": { "apsxj/json": "dev-main" }, "repositories": [ { "type": "git", "url": "https://github.com/apsxj/json.git" } ]
-
Run
composer install -
Before calling any of the methods, require the vendor autoloader
// For example, from the root directory... require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php');
- To create a
Responseobject and render it:
<?php // unwrap the Response class from the apsxj\json namespace use apsxj\json\Response; // Create a new response $response = new Response(); // Add some data $response->appendData( array( 'method' => 'test', 'result' => 'success' ) ); // Render the response $response->render();
Output should look something like this:
{ "links": { "self": "https:\/\/localhost\/api\/test" }, "meta": { "timestamp": 1620587659, "object": "dictionary", "count": 1 }, "data": [ { "method": "test", "result": "success" } ] }
- To create an error response and render it:
<?php // unwrap the Response class from the apsxj\json namespace use apsxj\json\Response; // Create a new response $response = new Response(); // Add the error $response->appendError( 404, 'Not Found', 'The requested resource was not found' ); // Render the response $response->render();
Output should look something like this:
{ "errors": [ { "status": 404, "title": "Not Found", "detail": "The requested resource was not found" } ] }