struktal / struktal-api
PHP library for creating consistent JSON APIs
Installs: 303
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/struktal/struktal-api
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.