PHP code example of adrianorosa / http-response-formatter

1. Go to this page and download the library: Download adrianorosa/http-response-formatter 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/ */

    

adrianorosa / http-response-formatter example snippets




use AdrianoRosa\HttpResponse\Response;

$data = ['foo' => 'bar'];

$response = Response::create()->safeJson($data);

// )]}',\n
// {"code":200,"status":"success","data":{"foo":"bar"}}



use AdrianoRosa\HttpResponse\Response;

$data = ['foo' => 'bar'];

$response = Response::create()->toJson($data);

// {"code":200,"status":"success","data":{"foo":"bar"}}