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

Http Laravel Package

react/http

Event-driven, streaming HTTP client and server for ReactPHP. Send many concurrent async HTTP/HTTPS requests, handle redirects/timeouts/auth, and stream request/response bodies. Build plain HTTP or secure HTTPS servers on ReactPHP Socket and EventLoop.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing via Composer (composer require react/http) and include the autoloader. The Browser class is your primary entry point for making async HTTP requests, while HttpServer is used to build event-driven HTTP servers. Begin with the quickstart examples in the README: a simple client fetching a URL and a basic server returning "Hello World!". Use Browser::get(), post(), etc., for clients, and wire HttpServer with a SocketServer for serving requests. All methods return Promises, so use then() for handling responses or errors.

Implementation Patterns

Use Browser with method chaining to configure clients (e.g., withTimeout(), withBase(), withFollowRedirects()). For servers, route requests by inspecting $request->getMethod() and $request->getUri()->getPath(), returning PSR-7 Response objects via static helpers like Response::json() or Response::html(). Implement middleware to decorate request handling (e.g., RequestBodyBufferMiddleware, custom logging or auth). Leverage streaming for large uploads/downloads: use requestStreaming() and ReadableStreamInterface/WritableStreamInterface for memory-efficient data pipelines. Combine LimitConcurrentRequestsMiddleware for rate limiting or StreamingRequestMiddleware for partial request body access.

Gotchas and Tips

  • Versioning: This package is in active v3 development; prefer the 1.x branch for production stability unless you’re testing early releases. Check release tags carefully.
  • Timeouts: Default timeout (60s) covers the full request including body receive and redirects unless streaming is used. Streamed responses/requests exclude body transfer time from the HTTP timeout—adjust socket-level timeout separately via Connector.
  • Blocking pitfalls: Do not use BlockingResponseStream in production; it’s only for CLI tools or scripts. Prefer async patterns throughout your stack.
  • Headers & bodies: Unbuffered bodies require Transfer-Encoding: chunked unless Content-Length is explicitly set. Never assume Content-Length is present or accurate—validate or buffer if needed.
  • Redirects: Authorization headers are not forwarded during redirects for security. Implement custom redirect logic if cross-origin auth is needed.
  • Middleware order matters: Apply RequestBodyParserMiddleware after buffering if you need parsed $_POST/php://input—but prefer direct stream access for async efficiency.
  • Debugging: Enable ReactPHP’s event loop debugging via Loop::get()->addTimer(0.1, ...), log request/response sizes, and use var_dump($response->getHeaders()) early to verify content types and status codes.
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
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
uri-template/tests