PHP code example of demartis / jttp

1. Go to this page and download the library: Download demartis/jttp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

demartis / jttp example snippets


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.']);



use Jttp\Jttp;
use Jttp\JttpResponse;
$data = ['field'=>'dummy data'];
$responseOkWithData = JttpResponse::ok($data);
$jttp = Jttp::createFromResponse($responseOkWithData);

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