Skip to main content

HTTP Client Tips & Tricks

Premium
7:33

In this final lesson of the course, we will have a "rapid fire" style list of various techniques, less-known syntax options and methods of Laravel HTTP Client. Let's go!


Section 1/4. Smart Retry Tips

Tip 1. Basic retry with exponential backoff

// Retry API calls with increasing delays (100ms, 200ms, 400ms)
$response = Http::retry(3, 100, function ($exception, $request) {
// Only retry on server errors or network issues
return $exception instanceof ConnectionException ||
($exception instanceof RequestException && $exception->response->serverError());
})->get('https://api.unstable-service.com/data');

Tip 2. Custom retry logic for specific error codes

// Retry only on specific HTTP status codes
$response = Http::retry(3, 1000, function ($exception, $request) {
if ($exception instanceof RequestException) {
$status = $exception->response->status();
// Retry on rate limiting (429) or server errors (5xx)
return $status === 429 || $status >= 500;
}
return false;
})->post('https://api.github.com/user/repos', $repoData);

...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

No comments yet…