struktal / struktal-api
PHP library for creating consistent JSON APIs
1.0.0
2025-08-21 07:36 UTC
Requires
- php: >=8.2.0
README
This is a PHP library for creating consistent JSON APIs
Installation
To install this library, include it in your project using Composer:
composer require struktal/struktal-api
Usage
You can send JSON responses using the methods in the struktal\API\API
class.
For example, to send any JSON response, you can use API::sendJson
:
\struktal\API\API::sendJson([ "field1" => "value1", "field2" => "value2" ]);
{ "field1": "value1", "field2": "value2" }
Alternatively, use the API::sendWrappedJson
method to send a structured JSON response with a status code and message:
\struktal\API\API::sendWrappedJson([ "field1" => "value1", "field2" => "value2" ], \struktal\API\HTTPResponse::OK);
{ "code": 200, "message": "Ok", "data": { "field1": "value1", "field2": "value2" } }
License
This software is licensed under the MIT license. See the LICENSE file for more information.