API Documentation

Build Coverage

HTTP Library documentation

The HTTP library has files that facilitate request and response processes, as well as providing classes for handling URLs, file uploads and downloads, as well as Cookies and GeoIP.


With the Request class you can get Object Oriented information about headers, URL, and request body.

To use the class just instantiate it:

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

use Framework\HTTP\Request;

$request = new Request();

That done, we can already get data from the headers:

$method = $request->getMethod(); // GET
$host = $request->getHeader('Host'); // localhost:8080
$secure = $request->isSecure(); // false
$ajax = $request->isAJAX(); // false


If the request is not secure, we can force a redirect using HTTPS:

$request->forceHTTPS(); // redirect and exit


When working with JSON, there are methods to check the request’s Content-Type header and get the data already decoded:

if ($request->isJSON()) {
    $data = $request->getJSON();

Request with uploads

To get a file, call it by name.

The getFile method returns an instance of UploadedFile or null.

$file = $request->getFile('name');


HTTP responses send headers and message body in addition to the code and the reason for the status.

To use the response class, just instantiate it as well:

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

use Framework\HTTP\Request;
use Framework\HTTP\Response;

$request = new Request();
$response = new Response($request); // an instance of Request is required

A response containing JSON could be set to:

$response->setHeader('content-type', 'application/json');
    'id' => 1,
    'name' => 'Mary',

or simply:

    'id' => 1,
    'name' => 'Mary',

Response with download

To send a file as a download in the response, you can call:


With the second parameter set to true the content disposition is inline, causing the browser to open the file in the window.

$response->setDownload('filepath.pdf', true);

The third parameter makes it possible to continue downloads or start downloading a video at a certain time.

$response->setDownload('filepath.pdf', true, true);


The library has a class for working with URLs.

use Framework\HTTP\URL;

$url = new URL('http://localhost:8080');
echo $url->getScheme(); // http
echo $url->getHost(); // localhost:8080
echo $url->getHost(); //
echo $url->getHost(); //