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

Requests Laravel Package

rmccue/requests

A simple, lightweight HTTP library for PHP. Requests provides an easy API for making GET/POST calls, handling headers, cookies, redirects, proxies, timeouts, and authentication, with support for transports like cURL and sockets.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer: composer require rmccue/requests. Start with the core Requests::request() method—no complex configuration needed for basic usage. For example:

use Requests;

$response = Requests::get('https://api.example.com/users/123');
echo $response->body; // Raw response body
echo $response->status_code; // 200

Look first at the Requests class static methods (get, post, etc.) and the Requests_Response object returned. The README’s “Usage” section gives minimal but sufficient examples for common GET/POST cases.

Implementation Patterns

  • Consistent Request Building: Wrap Requests in a service class that sets defaults (e.g., base URL, headers) for API clients. Use Requests::request($url, $headers, $data, $type, $options) to standardize retries or logging.
  • Async-like Parallel Requests: Use Requests::request_multiple() with an array of request configs—ideal for batch API calls without blocking.
  • Hook-Driven Auth/Logging: Register custom hooks via Requests::register_hook('request.before_send', $callback) to inject API keys, emit logs, or validate signatures globally.
  • Fallback Transports: Detect environment constraints and switch transports via Requests::set_transport() (e.g., force Requests_Transport_fsockopen in cURL-restricted hosting).
  • Stream Large Responses: Use 'stream' => true in options to process large downloads incrementally, avoiding memory issues.

Gotchas and Tips

  • No PSR-7 Compliance: Responses are not PSR-7 objects—do not expect interoperability with Symfony’s HttpClient or Guzzle middleware. Avoid mixing libraries that expect PSR-7 unless you convert manually.
  • Timeouts are in seconds, but default to 10s: Set 'timeout' => 30 explicitly for slow endpoints; missing this causes silent timeouts.
  • Cookies require cookiejar option: Cookies aren’t persisted by default. Use Requests::get($url, [], [], [], ['cookiejar' => '/path/to/cookie.txt']) or Requests_Cookie_Jar for state.
  • Redirects: Follow only HTTP 3xx by default—enable follow_redirects in options (set true or integer depth). HTTP 204 responses with Location headers won’t redirect.
  • Debugging: Enable Requests::set_debug(true); globally to log low-level request details— invaluable for transport-specific issues (e.g., open_basedir restrictions with fsockopen).
  • Extensibility: Extend Requests_Transport for custom backends (e.g., mock HTTP in tests), or use Requests::add_hook() to mutate requests/responses—perfect for audit trails or circuit breakers.
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
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
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