innmind / http
Value Objects to abstract http messages
8.0.0
2025-04-20 15:28 UTC
Requires
- php: ~8.2
- innmind/filesystem: ~8.0
- innmind/immutable: ~5.11
- innmind/io: ^3.0.1
- innmind/media-type: ^2.0.1
- innmind/time-continuum: ~4.1
- innmind/url: ~4.0
- innmind/validation: ~2.0
- ramsey/uuid: ~4.7
Requires (Dev)
- innmind/black-box: ~6.1
- innmind/coding-standard: ~2.0
- innmind/static-analysis: ^1.2.1
- symfony/process: ^6.2
- dev-develop
- 8.0.0
- 7.1.0
- 7.0.1
- 7.0.0
- 6.4.0
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.1
- 6.0.0
- 5.3.1
- 5.3.0
- 5.2.0
- 5.1.0
- 5.0.0
- 4.5.1
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.11.1
- 3.11.0
- 3.10.0
- 3.9.1
- 3.9.0
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- dev-master
- dev-fix-boundary
- dev-response-sender
- dev-simplify-headers
- dev-header-values-sequence
- dev-simplify-factories
- dev-attempt
- dev-cs
- dev-update-dependencies
- dev-reuse-workflows
- dev-status-code
- dev-static-analysis
- dev-blackbox-6
- dev-php-84-deprecations
- dev-license-date-range
This package is auto-updated.
Last update: 2025-04-20 15:29:24 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'), )), );