innmind / http
Value Objects to abstract http messages
9.0.0
2026-02-01 19:35 UTC
Requires
- php: ~8.4
- innmind/filesystem: ~9.0
- innmind/immutable: ~6.0
- innmind/io: ~4.0
- innmind/media-type: ~3.0
- innmind/time: ~1.0
- innmind/url: ~5.0
- innmind/validation: ~3.0
- ramsey/uuid: ~4.7
Requires (Dev)
- innmind/black-box: ~6.5
- innmind/coding-standard: ~2.0
- innmind/static-analysis: ~1.3
- symfony/process: ^6.2
This package is auto-updated.
Last update: 2026-06-15 13:18:00 UTC
README
Immutable value objects and interfaces to abstract http messages.
Important: you must use vimeo/psalm to make sure you use this library correctly.
Build a ServerRequest
use Innmind\Http\Factory\ServerRequestFactory; use Innmind\TimeContinuum\Clock; $request = ServerRequestFactory::native(Clock::live())();
Send a Response
use Innmind\Http\{ Response, Response\StatusCode, Response\Sender\Native, ProtocolVersion, Headers, Header, Header\ContentType, }; use Innmind\Filesystem\File\Content; use Innmind\TimeContinuum\Clock; $response = Response::of( StatusCode::ok, ProtocolVersion::v11, Headers::of( ContentType::of('application', 'json'), ), Content::ofString('{"some": "data"}'), ); Native::of(Clock::live()))($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"}
Build a multipart Request
use Innmind\Http\{ Request, Method, Content\Multipart, Header\ContentType\Boundary, Headers, ProtocolVersion, }; use Innmind\Filesystem\{ File, File\Content, }; use Innmind\Url\Url; $boundary = Boundary::uuid(); $request = Request::of( Url::of('http://some-server.com/') Method::post, ProtocolVersion::v11, Headers::of($boundary->toHeader()), Multipart::boundary($boundary) ->with('some[key]', 'some value') ->withFile('some[file]', File::named( 'whatever.txt', Content::ofString(' can be any file content'), )), );