Courses

Laravel HTTP Client and 3rd-Party APIs

HTTP Client Tips & Tricks

You're reading a FREE PREVIEW of a PREMIUM course.

Video Version of the Lesson

[Only for premium members]

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 7 video+text lessons of this course? (50 min)

You also get:

  • 83 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord