ringcentral/psr7
PSR-7 HTTP message implementation built on Zend Diactoros, tailored for RingCentral integrations. Provides request/response, streams, URIs, and uploaded files with familiar interfaces for interoperable HTTP clients, middleware, and SDKs.
Install the package via Composer:
composer require ringcentral/psr7
Begin by leveraging its immutable PSR-7 implementations—especially ServerRequest, Request, Response, Stream, and Uri. Start with constructing a simple request or response:
use RingCentral\Psr7\Request;
use RingCentral\Psr7\Response;
$request = new Request('GET', 'https://api.example.com/users');
$response = new Response(200, ['Content-Type' => 'application/json'], '{"status":"ok"}');
For common use cases (e.g., handling incoming HTTP requests in a standalone script or middleware stack), parse a raw request or use ServerRequestFactory::fromGlobals() if combined with a compatible factory (note: this package does not include factories—see “Gotchas” below).
ServerRequestInterface objects through middleware pipelines, modifying via fluent setters:
$request = $request->withQueryParams(['page' => 2])
->withHeader('X-Custom', 'value');
Stream objects:
$stream = new Stream('php://temp', 'r+');
$stream->write(json_encode($data));
$response = new Response(200, [], $stream);
$uri = (new Uri('https://api.example.com'))
->withPath('/users')
->withQuery('limit=10');
$request = $request->withUri($uri);
ringcentral/psr7 only implements interfaces, pair it with a factory like nyholm/psr7-factory or laminas/laminas-diactoros for ServerRequest creation from globals:
$factory = new Nyholm\Psr7\Factory\Psr17Factory();
$request = $factory->createServerRequest('GET', '/api');
nyholm/psr7-factory, slim/php-http-psr7 for Slim) to create ServerRequestInterface instances from $_SERVER, $_GET, etc.with*() methods (e.g., $req = $req->withHeader(...)); forgetting to reassign is a common source of silent bugs.fopen(...)) may not be rewound automatically. Call $stream->rewind() after writes or before reads if needed.Date headers to be in RFC 7231 format. Use \DateTime::RFC7231 when setting them manually.ringcentral/psr7 against alternatives (e.g., nyholm/psr7 or slim/psr7); while lightweight, some implementations are faster for large payloads or high-frequency operations.PEAR::HTTP_Request2) may conflict if mixed with older code.How can I help you explore Laravel packages today?