HTTP Client That Handles Retries and Logging

HTTP Client That Handles Retries and Logging

Gustavo Ocanto created an HTTP client on top of Guzzle that handles retries and logging. Typically you’d have some code like the following (and likely a try/catch too) if you need to retry an HTTP call:

use GuzzleHttp\Client;

$retry = 1;
$response = null;

do {
    $response = (new Client)->get('http://foo.com');
} while ($response === null && $retry <= 5);

With this client, you can achieve similar with the following code:

$response = (new Client)->retry(5)->get('http://foo.com'); 

If you need more granular control and want to tap into the retry routine, the package has an onRetry method:

$response = (new Client)->onRetry(function () {
    // Do stuff
})->get('http://foo.com'); 

You can learn more about this package, get full installation instructions, and view the source code on GitHub at gocanto/http-client.


Filed in: News / packages


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

PHP Data Engineer
Remote (US)
FBS
Software Developer
Remote (US & Canada)
Alley
Backend Software Engineer
Remote (UTC +/- 5)
Smartbnb
Programmer
Remote (Overlap w/ Continental US Time Zones)
Tighten
Senior Backend Engineer
Remote
64 Robots
Senior Laravel Developer
Atlanta, GA
Helium LLC
Full-Stack Developer (JS - Vue.js, PHP - Laravel)
US Remote / Telecommute
TTEC Digital