Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Http Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Asynchronous/Concurrent Requests: Use Client::setOptions(['adapters' => [...]]) with Curl or Stream adapter, or plug in custom adapters via ClientInterface.
  • Middleware-style Pipelines: Wrap Client in custom middleware to add logging, retry logic, or rate limiting without breaking HTTP semantics.
  • Content Negotiation: Leverage Header\Accept and Header\ContentType classes to enforce or inspect Accept and Content-Type headers automatically during serialization/deserialization.
  • Stateful Session Handling: Use Header\SetCookie and Header\Cookie to persist session cookies across requests — especially useful in CLI tools or microservices.
  • Testing Integration: Stub Client in unit tests with getMock() and assert against Request/Response objects without hitting real endpoints.

Gotchas and Tips

  • Message Mutability: Request and Response objects are mutable — be careful with reuse across threads or long-lived services; clone before passing to async queues.
  • Header Case Sensitivity: Laminas normalizes header names (e.g., content-typeContent-Type), but Header\HeaderInterface::getFieldValue() returns normalized strings — don’t rely on raw casing when matching.
  • Redirect Handling: By default, Client follows redirects (up to 5); disable with $client->setOptions(['maxredirects' => 0]), or customize via Redirect plugin if needing complex logic.
  • Large Body Streaming: Avoid loading large responses into memory — use $response->getBody() as a stream resource ($response->getStream()) with fread() or stream_copy_to_stream().
  • Custom Adapters: Extend Client\Adapter\AdapterInterface for proxy/tunneling or mock network conditions (e.g., latency injection in tests).
  • RFC Compliance: While headers/body parsing is robust, non-compliant servers (e.g., missing CRLF terminators) may cause parse failures — wrap send() in try/catch and fallback to raw stream_get_contents().
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation