Table of Contents

Requests (HTTP)

Requests are not a separate component, but are part of a larger component which provides specific input / output components for your application. The most common request is HTTP requests. This is what is documented here.

Requests are designed for both receiving (from clients as a server) and sending (as client to a server).


composer require dotink/inkwell-http

You do not need to explicitly install this package if you're using the inKWell routing package.


Although you can instantiate an empty request and work with it directly, in most cases you're going to want your request to be populated from the data provided by the SAPI. In order to do this you can create a gateway server and populate the request.

use Inkwell\HTTP;

$request = new HTTP\Resource\Request();
$gateway = new HTTP\Gateway\Server();


Getting / Setting

There are a number of properties you can get/set on the request itself or on components which are directly relatedo the request.


The URL is held in a URL object which provides a number of additional methods, see: To get the URL object you need to use the getURL() method:

$url = $this->request->getURL();

Additionally there are methods on the URL object for retrieving separate pieces:

$host = $this->request->getURL()->getHost();
$path = $this->request->getURL()->getPath();

You can set partial aspects of the URL, thereby modifying it:


HTTP Method

Get the method:

$method = $request->getMethod();

Check the method:

use IW\HTTP;

if ($request->checkMethod(HTTP\POST)) {
	// Do some posting

Set the method:

use IW\HTTP;


HTTP Headers

You can get or set headers on a request by working with the headers property which is populated as an instance of Dotink\Flourish\Collection, see:

$accept = $this->request->headers->get('Accept');

You can get all headers as an array via:

$headers = $this->request->headers->get()

Set a specific header by doing:

$this->request->headers->set('X-Forwarded-For', $ip_address);

Set multiple headers with an array:

	'Accept-Language' => $this->request->cookies->get('lang'),
	'X-Custom-Header' => $value

Parameter Data

Get data:

$name = $this->request->params->get('name');

Provide a default:

$page = $this->request->params->get('page', 1);

Get nested data:

$name = $this->request->params->get('', 'Jesse Doe');

Get all the data:

$params = $this->request->params->get();

Set data:

$this->request->params->set('task', $next_task->getId());

Set nested data:

$this->request->params->set('person.age', 30);


Get a cookie value:

$user_token = $this->request->cookies->get('user_token', NULL);


Get a file:

$document = $this->request->files->get('document');

Get a nested file:

$profile_image = $this->request->files->get('user.profile_image');