https://github.com/demartis/jttp-php
A simple PHP implementation of the JTTP specification
https://github.com/demartis/jttp-php
json jttp php response rest-api standard
Last synced: 5 months ago
JSON representation
A simple PHP implementation of the JTTP specification
- Host: GitHub
- URL: https://github.com/demartis/jttp-php
- Owner: demartis
- License: bsd-2-clause
- Created: 2020-09-11T07:44:18.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-01T09:25:50.000Z (over 5 years ago)
- Last Synced: 2025-11-27T14:50:11.415Z (7 months ago)
- Topics: json, jttp, php, response, rest-api, standard
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JTTP
A simple PHP implementation of the [JTTP specification](https://github.com/demartis/jttp).
- [GitHub project](https://github.com/demartis/jttp-php)
- [Composer package](https://packagist.org/packages/demartis/jttp)
## Usage
```php
use Jttp\JttpResponse;
$data = ['field'=>'dummy data'];
$success = JttpResponse::ok($data);
$success = JttpResponse::success(200, "OK", $data);
$error = JttpResponse::error(401, null, ['Not cool.']);
$errorWithMessage = JttpResponse::error(401, 'not authorized', ['Not cool.']);
```
Create Jttp object from JttpResponse:
```php
use Jttp\Jttp;
use Jttp\JttpResponse;
$data = ['field'=>'dummy data'];
$responseOkWithData = JttpResponse::ok($data);
$jttp = Jttp::createFromResponse($responseOkWithData);
```
Create Jttp object from simple response array:
```php
use Jttp\Jttp;
use Jttp\JttpResponse;
$res = array(
"status" => "success",
"code" => 200,
"message"=> "OK",
"data"=> ['field'=>'dummy data']
);
$jttp = Jttp::createFromJttpArray($res);
// get status
$jttp->getStatus(); // 'success'
$jttp->isSuccess(); // true
$jttp->getData(); // ['field'=>'dummy data']
```