Skip to content

cherry-framework/response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cherry-Response

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