rmccue/requests
Requests is a human-friendly PHP HTTP client for sending GET/POST/PUT/DELETE/PATCH/HEAD requests with headers, auth, files, and parameters. Supports cURL or fsockopen, SSL verification, decompression, and IDN URLs with a consistent API.
Pros:
Requests::get(), Requests::post()) is intuitive for PHP developers familiar with Laravel’s Eloquent or HTTP clients.WpOrg\Requests\Session) mirrors Laravel’s HTTP client session persistence, useful for APIs requiring cookies/auth headers across requests.TrustProxies middleware).art4/requests-psr18-adapter enables integration with Laravel’s PSR-18-compliant HTTP client stack (e.g., Illuminate\Http\Client).Cons:
HttpClient facade) or frameworks like Lumen.Swoole or ReactPHP integrations).Guzzle client for simple use cases (though Guzzle is preferred for advanced features like middleware).AppServiceProvider (e.g., binding WpOrg\Requests\Requests to an interface).Http and MockHttp testing helpers, though response objects differ from Guzzle’s.Http::get() calls with Requests::get() in legacy codebases.art4/requests-psr18-adapter to unify with Laravel’s HttpClient facade for new projects.Requests responses and Laravel’s Illuminate\Http\Response objects.mixed return types in responses).fsockopen transport (if cURL is unavailable).retry middleware).HttpClient may be better.art4/requests-psr18-adapter.cURL calls that could be refactored to Requests?Requests\Response objects be mocked in PHPUnit?
Laravel’s MockHttp may need custom extensions.Http::get() with Requests::get() for lightweight APIs.WpOrg\Requests\Requests to an interface (e.g., HttpClientInterface) for dependency injection.Requests responses to Laravel’s Illuminate\Http\Response.Phase 1: Pilot Replacement
Http::get('https://api.example.com/data')) with:
$response = Requests::get('https://api.example.com/data');
return response()->json($response->body);
Requests_Exception vs. Laravel’s HttpException).Phase 2: Adapter Layer
art4/requests-psr18-adapter) to integrate with Laravel’s HttpClient facade:
use Art4\RequestsPsr18Adapter\RequestsClient;
$client = new RequestsClient();
$response = $client->get('https://api.example.com');
$this->app->bind(\Psr\Http\Client\ClientInterface::class, function ($app) {
return new RequestsClient();
});
Phase 3: Session Management
Http::withToken()) with Requests\Session:
$session = new \WpOrg\Requests\Session('https://api.example.com');
$session->auth = ['token' => 'abc123'];
$response = $session->get('/data');
Phase 4: Full Replacement
Http facade calls with the adapter or direct Requests usage.Requests responses.| Feature | Compatibility Notes |
|---|---|
| HTTP Methods | Supports all standard methods (GET, POST, PUT, DELETE, PATCH, HEAD). |
| Headers | Case-insensitive; manual Content-Type required for non-form data. |
| Authentication | Basic/Digest auth supported; OAuth requires manual header setup. |
| SSL/TLS | Automatic verification; custom CA paths supported. |
| Cookies | Session object handles cookies; no built-in cookie jar like Guzzle. |
| Redirects | Follows redirects by default (configurable). |
| Timeouts | Configurable via $options['timeout']. |
| Async | Not supported (blocking I/O). |
| Streaming | Limited; responses must be fully loaded into memory. |
| Middleware | Not supported (unlike Guzzle). |
GET requests) where failures are less impactful.Requests responses in unit tests before full migration.Requests\ResponseHow can I help you explore Laravel packages today?