Alexya's HTTP components

Installs: 59

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:framework

3.0.2 2017-06-05 14:14 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:45:56 UTC


README

Alexya's HTTP components

Contents

Request

The class \Alexya\Http\Request offers a wrapper for the request supergloblas ($_GET, $_POST...).

You can retrieve the request with the method main.

The constructor accepts the following parameters:

  • A string being the requested URI.
  • An array being GET parameters.
  • An array being POST parameters.
  • An array being COOKIE parameters.
  • An array being SERVER parameters.

Example:

<?php

$request = new \Alexya\Http\Request(
    $_SERVER["REQUEST_URI"],
    $_GET,
    $_POST,
    $_COOKIES,
    $_FILES,
    $_SERVER
); // Which is the same as `$request = \Alexya\Http\Request::main();`

echo $request->get["param_name"];

foreach($request->headers as $key => $value) {
    echo "Requested header: {$key}: {$value}";
}

Response

The class \Alexya\Http\Response offers a way for create and send HTTP responses.

The constructor accepts the following parameters (all of them optional):

  • An array being the headers.
  • A string being the response body.
  • An integer being the status code (or a string being the status name).

To send the request use the method send.

To add a new header use the method header which accepts as parameter a string being the header name and a string or an array being the value of the header.

The method status sets the status code of the response, it can be either an integer being the code or a string being the name (see Response::responseCodes).

The method redirect sends a redirect response thrugh headers. It accepts as parameter a string being the URL to redirect, a string being the method of redirect ("Refresh" or "Location") and the status code of the redirect.

Example:

<?php

$request = new Request();

$request->header("Content-Type", "text/html");
$request->status(200);
$request->body("<h1>Hello World</h1>");

Request::redirect("/Home");