nyholm/psr7
Nyholm PSR-7 is a super lightweight, strict, and fast implementation of PSR-7 with full PSR-17 factories and HTTPlug/PSR-18 compatibility. Create requests, streams, URIs, and server requests with minimal overhead.
Install with composer require nyholm/psr7. This is the minimal, strict PSR-7 implementation—no extra helpers, no fluff. Begin by instantiating Nyholm\Psr7\Factory\Psr17Factory, the sole entrypoint for creating PSR-7 objects. For common use cases like server requests, pair it with nyholm/psr7-server to build ServerRequest from superglobals ($_GET, $_POST, etc.). To emit responses, use any PSR-15/17/18-compatible emitter (e.g., laminas/laminas-httphandlerrunner). It’s compatible with Symfony Flex (auto-registers factories as services).
Psr17Factory (e.g., createRequest(), createStream(), createResponse()). Avoid direct instantiation—PSR-7 requires immutable objects, and the factory ensures correct compliance.$request = $factory->createRequest(...)->withHeader(...)->withBody(...). Prefer method chaining over modification.Psr17Factory with any PSR-18 client (e.g., guzzlehttp/guzzle, curl, or buzz). Example: $client->sendRequest($factory->createRequest('POST', $url)->withBody($factory->createStream($json))).nyholm/psr7-server’s ServerRequestCreator::fromGlobals() to convert PHP superglobals into PSR-7 ServerRequest for middleware or framework integration.json(), toDto(), or convenience methods—roll your own helpers if needed.withHeader()) return new instances—never mutate in-place. Accidentally ignoring return values is a common bug.Stream::getContents() throws exceptions on non-seekable resources (fixed in 1.8.1); avoid calling __toString() on large streams (use fopen('php://memory') for large data).getParsedBody() is populated on creation only for application/x-www-form-urlencoded and multipart/form-data; raw bodies require manual parsing via getContents().ValueError, nullability). Use Psr17Factory—HttplugFactory is deprecated (removed in next major).@final signals intentional immutability.How can I help you explore Laravel packages today?