slim/psr7
Slim PSR-7 is a strict PSR-7 HTTP message implementation used by the Slim Framework. Use it standalone in any PSR-7 compatible project to create and work with requests, responses, streams, and URIs. Requires PHP 8.0+.
Install via Composer:
composer require slim/psr7
This package provides a strict, production-ready PSR-7 implementation (implementing both MessageInterface, RequestInterface, ResponseInterface, ServerRequestInterface, UploadedFileInterface, UriInterface, and factory interfaces via Psr7Factory). Although originally built for Slim 4, it works standalone in any PSR-7-compatible framework or standalone application.
First practical use case:
use Slim\Psr7\Factory\ServerRequestFactory;
$factory = new ServerRequestFactory();
$request = $factory->createServerRequest('GET', '/api/users?limit=10');
You’ll typically use the Slim\Psr7\Factory classes (ServerRequestFactory, RequestFactory, ResponseFactory, StreamFactory, UploadedFileFactory, UriFactory) to construct PSR-7 objects programmatically (e.g., in tests or micro-frameworks), or let your framework do it automatically.
ServerRequestFactory to mock incoming requests with arbitrary headers, cookies, files, and parsed body:
$request = (new ServerRequestFactory())->createServerRequest(
'POST',
'/upload',
['HTTP_CONTENT_TYPE' => 'multipart/form-data']
)->withParsedBody(['name' => 'test'])->withUploadedFiles([...]);
HttpFactoryDiscovery + Slim\Psr7\Factory\ServerRequestFactory as a fallback).$response = (new ResponseFactory())->createResponse(201);
$response->getBody()->write(json_encode(['id' => 123]));
$response = $response->withHeader('Content-Type', 'application/json');
Slim\Psr7\Header (internal, but safely accessible) to parse/normalize headers, or rely on Request/Response’s native getHeaderLine() / getCookieParams().<1.7.with* methods return new instances—accidentally ignoring return values is a common source of bugs.^1.8.0+ for RFC 6265-compliant Set-Cookie headers.Uri::getPath() now correctly strips leading slashes for relative paths (v1.4.2+). Avoid manual path concatenation.1.4.1, 1.5.1, 1.6.1) requires updating if on older patch versions—always pin to latest patch.Slim\Psr7\Factory\ServerRequestFactory (e.g., custom stream class) and injecting your own.How can I help you explore Laravel packages today?