2017 © Pedro Peláez
 

library http

Basic http layer.

image

weew/http

Basic http layer.

  • Thursday, November 3, 2016
  • by weew
  • Repository
  • 1 Watchers
  • 0 Stars
  • 286 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 50 Versions
  • 0 % Grown

The README.md

HTTP layer for PHP

Build Status Code Quality Test Coverage Version Licence, (*1)

Table of contents

Installation

composer require weew/http, (*2)

Responses

Basic response

$response = new HttpResponse();
$response->send();
HTTP/1.1 200 OK
Host: localhost
Connection: close



### Content ```php $response = new HttpResponse(); $response->setContent('<h1>Hello World!</h1>'); $response->send();

HTTP/1.1 200 OK Host: localhost Connection: close content-type: text/html, (*3)

Hello World!


### Status codes ```php $response = new HttpResponse(HttpStatusCode::UNAUTHORIZED); // or $response = new HttpResponse(401); $response->send();
HTTP/1.1 401 Unauthorized
Host: localhost
Connection: close



### Headers ```php $response = new HttpResponse(); $response->getHeaders()->set('foo', 'bar'); $response->send();

HTTP/1.1 200 OK Host: localhost Connection: close foo: bar, (*4)


### Cookies ```php $response = new HttpResponse(); $response->getQueuedCookies()->add(new Cookie('foo', 'bar')); $response->send();
HTTP/1.1 200 OK
Host: localhost
Connection: close
set-cookie: foo=bar; path=/; httpOnly



## Custom responses ### HtmlResponse ```php $response = new HtmlResponse(); $response->setHtmlContent('<h1>Hello World!</h1>'); $response->send();

HTTP/1.1 200 OK Host: localhost Connection: close content-type: text/html, (*5)

Hello World!


### JsonResponse ```php $response = new JsonResponse(); $response->getData()->set('Hello', 'World!'); $response->send();
HTTP/1.1 200 OK
Host: localhost
Connection: close
content-type: application/json

{"Hello":"World!"}



### BasicAuthResponse ```php $response = new BasicAuthResponse('Please login'); $response->send();

HTTP/1.1 200 OK Host: localhost Connection: close www-authenticate: basic realm="Please login", (*6)


## Requests ### Basic request It is very easy to build a custom request. ```php $request = new HttpRequest( HttpRequestMethod::POST, new Url('http://example.com') ); $request->setContent('foo=bar');

GET parameters

$request = new HttpRequest();
$request->getUrl()->getQuery()->set('foo', 'bar');

echo $request->getUrl()->getQuery();
// foo=bar

POST data

$request = new HttpRequest();
$request->getData()->set('foo', 'bar');
$request->getData()->set('bar', 'foo');

echo $request->getContent();
// foo=bar&bar=foo

Headers

You can access headers the same way as on the HttpResponse class., (*7)

$request = new HttpRequest();
$request->getHeaders()->set('foo', 'bar');
$request->getHeaders()->add('foo', 'foo');

var_dump($request->getHeaders()->get('foo'));
// ['bar', 'foo']
echo $request->getHeaders()->find('foo');
// foo

Current Request

Sometimes it is nice to have an object that would represent the current received http request., (*8)

$request = new CurrentRequest();
var_dump($request->toArray());
// all the data that the server received from the client

Basic Authentication

It is very easy to authenticate a request via basic auth., (*9)

$request = new HttpRequest();
$request->getBasicAuth()->setUsername('foo');
$request->getBasicAuth()->setPassword('bar');
echo $request->getBasicAuth()->getToken();
// Zm9vOmJhcg==
echo $request->getHeaders()->find('authentication');
// Basic Zm9vOmJhcg==
  • URL: used throughout the project.
  • HTTP Client: a simple http client that allows you to send and receive the standardized HttpRequest and HttpResponse objects.

The Versions

02/06 2016

v1.10.0

1.10.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

22/04 2016

v1.9.1

1.9.1.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

22/03 2016

v1.9.0

1.9.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

08/03 2016

v1.8.0

1.8.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

22/02 2016

v1.7.0

1.7.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

22/02 2016

v1.6.0

1.6.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

26/01 2016

v1.5.1

1.5.1.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

26/01 2016

v1.5.0

1.5.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

21/01 2016

v1.4.0

1.4.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

20/01 2016

v1.3.0

1.3.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

18/01 2016

v1.2.1

1.2.1.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

13/01 2016

v1.2.0

1.2.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0
  • weew/php-helpers-string ^1.0
  • weew/php-url ^1.0
  • weew/php-contracts ^1.1
  • weew/php-json-encoder ^1.0

 

The Development Requires

by Maxim Kott

18/11 2015

v1.1.0

1.1.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-url ^1.0.0
  • weew/php-contracts ^1.1

 

The Development Requires

by Maxim Kott

16/11 2015

v1.0.0

1.0.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation ^1.0.0
  • weew/php-helpers-array ^1.0.0
  • weew/php-helpers-string ^1.0.0
  • weew/php-url ^1.0.0

 

The Development Requires

by Maxim Kott

26/08 2015

v0.1.19

0.1.19.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

24/08 2015

v0.1.18

0.1.18.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

24/08 2015

v0.1.17

0.1.17.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

24/08 2015

v0.1.16

0.1.16.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

21/08 2015

v0.1.15

0.1.15.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

14/08 2015

v0.1.14

0.1.14.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

14/08 2015

v0.1.13

0.1.13.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

14/08 2015

v0.1.12

0.1.12.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

13/08 2015

v0.1.11

0.1.11.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

13/08 2015

v0.1.10

0.1.10.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.9

0.1.9.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.8

0.1.8.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.7

0.1.7.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.6

0.1.6.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.5

0.1.5.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.4

0.1.4.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.3

0.1.3.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

12/08 2015

v0.1.2

0.1.2.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

11/08 2015

v0.1.1

0.1.1.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

31/07 2015

v0.1.0

0.1.0.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

29/07 2015

v0.0.11

0.0.11.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

29/07 2015

v0.0.10

0.0.10.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

29/07 2015

v0.0.9

0.0.9.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

23/07 2015

v0.0.8

0.0.8.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

23/07 2015

v0.0.7

0.0.7.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

23/07 2015

v0.0.6

0.0.6.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

23/07 2015

v0.0.5

0.0.5.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

22/07 2015

v0.0.4

0.0.4.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

22/07 2015

v0.0.3

0.0.3.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

22/07 2015

v0.0.2

0.0.2.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott

21/07 2015

v0.0.1

0.0.1.0

Basic http layer.

  Sources   Download

MIT

The Requires

  • weew/php-foundation 0.*
  • weew/php-helpers-array 0.*
  • weew/php-helpers-string 0.*
  • weew/php-url 0.*

 

The Development Requires

by Maxim Kott