demartis/jttp

PHP implementation of JTTP standard protocol for REST

1.3.0 2020-09-15 16:03 UTC

This package is auto-updated.

Last update: 2024-10-16 01:38:34 UTC


README

A simple PHP implementation of the JTTP specification.

Usage

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:

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:

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']