2017 © Pedro Peláez
 

library http

image

robert/http

  • Monday, September 7, 2015
  • by robert-horvath
  • Repository
  • 1 Watchers
  • 0 Stars
  • 68 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Latest Stable Version Minimum PHP Version, (*1)

HTTP

The HTTP module provides the required interfaces for handling the HTTP communication., (*2)

HTTP Requet Interface

This interface contains the required funcionalities for handling an HTTP request message., (*3)

Example usage

Get properties of an HTTP request message., (*4)

use RHo\Http\Request;

function example(RequestInterface $request): void {
    var_dump($request->isHttpsScheme());
    var_dump($request->method());
    var_dump($request->uri());
}

If the below HTTP request was received by server:, (*5)

GET /new-users/ HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: ela.do
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

By calling the example function, it will print out the following answer. ```, (*6)

## HTTP Response Interface
This interface contains the required funcionalities for sending an HTTP response message.
### Example usage
Builds and sends an HTTP response message.
```php
use RHo\Http\Response;

function replyWithBadRequest(ResponseInterfaceBuilder $builder): void {
    $builder->init(StatusCode::BadRequest)
        ->withHeader('Content-Type', 'application/prs.api.ela.do+json;version=1') // optional
        ->withBody('{ "apple": "tree" }')  // optional
        ->build()
        ->send();
}

By calling the replyWithBadRequest function, it will send the below HTTP response message., (*7)

HTTP/1.1 400 Bad Request
Content-Type: application/prs.api.ela.do+json;version=1
Content-Length: 19

{ "apple": "tree" }

HTTP Exception Interface

This interface contains the required funcionalities for throwing an exception with an HTTP response message., (*8)

use RHo\Http;

try {
    // HTTP handling
}
catch (ExceptionInterface $ex) {
    $ex->response()->send();
    exit(-1);
}

HTTP Router Interface

The router interface helps to find the right controller for a given user request., (*9)

Example usage

use RHo\Http;

$router = Router::buildWithRoutingTable([
    '/new-users' => NewUserCtrl::class,
    '/users' => UserCtrl::class,
    '/' => RootCtrl::class
]);
$ctrl = Controller::build($router);
}

HTTP Controller Interface

The controller interface is the main handler of the HTTP request and response messages. The below example shows an end to end handling of such communication., (*10)

Example usage

use RHo\Http;

function main(ControllerInterface $ctrl): void {
    try {
        do {
            $ctrl->validateRequest();
        } while ($ctrl->nextController());
        $ctrl->runService();
        $ctrl->sendResponse();
    }
    catch (ExceptionInterface $ex) {
        $ex->response()->send();
        exit(-1);
    }
}

The Versions

07/09 2015

dev-master

9999999-dev

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

07/09 2015

1.0.5

1.0.5.0

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

02/09 2015

1.0.4

1.0.4.0

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

27/08 2015

1.0.3

1.0.3.0

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

17/07 2015

1.0.2

1.0.2.0

  Sources   Download

BSD-3-Clause

The Requires

 

17/07 2015

1.0.1

1.0.1.0

  Sources   Download

BSD-3-Clause

The Requires

 

15/07 2015

1.0.0

1.0.0.0

  Sources   Download

BSD-3-Clause

The Requires