laminas/laminas-http
Laminas HTTP component providing HTTP client, request/response objects, headers and URI utilities for PHP applications. Useful for building and consuming web services, handling redirects, cookies, and proxy/adapter-based transports.
Start by installing the package via Composer: composer require laminas/laminas-http. The core classes live under Laminas\Http namespace — key entry points are Client for outbound requests, Request and Response for message objects, and Header\HeaderInterface implementations for header handling.
The first practical use case is building a simple REST client:
use Laminas\Http\Client;
use Laminas\Http\Request;
$client = new Client('https://api.example.com/users');
$response = $client->setMethod(Request::METHOD_GET)->send();
if ($response->isSuccess()) {
$data = json_decode($response->getBody(), true);
}
Check src/Client.php and src/Request.php in the repo for concrete examples — the minimal docs typically include inline docblocks.
Client::setOptions(['adapters' => [...]]) with Curl or Stream adapter, or plug in custom adapters via ClientInterface.Client in custom middleware to add logging, retry logic, or rate limiting without breaking HTTP semantics.Header\Accept and Header\ContentType classes to enforce or inspect Accept and Content-Type headers automatically during serialization/deserialization.Header\SetCookie and Header\Cookie to persist session cookies across requests — especially useful in CLI tools or microservices.Client in unit tests with getMock() and assert against Request/Response objects without hitting real endpoints.Request and Response objects are mutable — be careful with reuse across threads or long-lived services; clone before passing to async queues.content-type → Content-Type), but Header\HeaderInterface::getFieldValue() returns normalized strings — don’t rely on raw casing when matching.Client follows redirects (up to 5); disable with $client->setOptions(['maxredirects' => 0]), or customize via Redirect plugin if needing complex logic.$response->getBody() as a stream resource ($response->getStream()) with fread() or stream_copy_to_stream().Client\Adapter\AdapterInterface for proxy/tunneling or mock network conditions (e.g., latency injection in tests).send() in try/catch and fallback to raw stream_get_contents().How can I help you explore Laravel packages today?