cherry-project/response

Cherry-project Response class

v1.0.1 2019-03-28 16:20 UTC

This package is auto-updated.

Last update: 2024-11-29 03:58:26 UTC


README

The Cherry-project Response wrapper

GitHub license

GitHub release

Packagist Version

Including

Install from composer composer require cherry-project/response

Include Autoloader in your main file (Ex.: index.php)

require_once __DIR__ . '/vendor/autoload.php';

Class Request

Import class

use Cherry\HttpUtils\Response;

Crete class new object

$response = new Response();

Prepare data for transmission (Ex.: Array)

$arr = [
    'test' => 'vTest',
    'test2' => [
        'test2.1' => '2.1',
        'test2.2' => [
            'test2.2.1' => '2.2.1'
        ]
    ]
];

For sending response use sendResponse() method

The method takes 3 arguments:

  • Content (Required; Mixed) - The data for returning;
  • Status Code (Optional; 200 by default; Integer) - The HTTP Status Code;
  • HTTP Headers (Optional; empty by default; Key => Value Array) - The HTTP Headers;
echo $response->sendResponse(json_encode($arr), 200, ['Content-Type' => 'application/json']);

2019 © Cherry-project