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.
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.
Requests::request($url, $headers, $data, $type, $options) to standardize retries or logging.Requests::request_multiple() with an array of request configs—ideal for batch API calls without blocking.Requests::register_hook('request.before_send', $callback) to inject API keys, emit logs, or validate signatures globally.Requests::set_transport() (e.g., force Requests_Transport_fsockopen in cURL-restricted hosting).'stream' => true in options to process large downloads incrementally, avoiding memory issues.'timeout' => 30 explicitly for slow endpoints; missing this causes silent timeouts.cookiejar option: Cookies aren’t persisted by default. Use Requests::get($url, [], [], [], ['cookiejar' => '/path/to/cookie.txt']) or Requests_Cookie_Jar for state.follow_redirects in options (set true or integer depth). HTTP 204 responses with Location headers won’t redirect. Requests::set_debug(true); globally to log low-level request details— invaluable for transport-specific issues (e.g., open_basedir restrictions with fsockopen).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.How can I help you explore Laravel packages today?