innmind/http

Value Objects to abstract http messages

4.2.0 2020-02-15 14:50 UTC

README

develop
codecov
Build Status
Type Coverage

Value objects and interfaces to abstract http messages (because PSR7 didn't go far enough).

Build a ServerRequest

use Innmind\Http\Factory\ServerRequest\ServerRequestFactory;

$request = ServerRequestFactory::default()();

Send a Response

use Innmind\Http\{
    Message\Response\Response,
    Message\StatusCode,
    Message\ReasonPhrase,
    ProtocolVersion,
    Headers,
    Header,
    Header\ContentType,
    Header\ContentTypeValue,
    ResponseSender,
};
use Innmind\Stream\Readable\Stream;

$response = new Response(
    $code = StatusCode::of('OK'),
    $code->associatedReasonPhrase(),
    new ProtocolVersion(1, 1),
    Headers::of(
        new ContentType(
            new ContentTypeValue(
                'application',
                'json',
            ),
        ),
    ),
    Stream::ofContent('{"some": "data"}'),
);

(new ResponseSender)($response);

will build the following message:

HTTP/1.1 200 OK
Date: Wed, 04 May 2016 14:24:14 +0000
Content-Type : application/json

{"some": "data"}