Let's explore more complex HTTP Client usage by building a Discord webhook notification to alert your community when new tutorials are published.
We will send a message to the Discord server after submitting this long form:

This is the message we'll see on Discord:

Discord doesn't provide an official PHP package, unlike many APIs, so we must use the Laravel HTTP Client.
What You'll Learn
By the end of this lesson, you will learn how to:
- Send POST requests with complex JSON structures and nested data
- Retries: implement exponential backoff with jitter in cases when webhook doesn't work from the first attempt
Setting Up Your Discord Webhook
Discord webhooks are HTTP endpoints that allow external applications to send messages directly to Discord channels.
Before diving into code, you need a webhook URL from Discord:
- Navigate to your Discord server → Server Settings → Integrations
- Click "Create Webhook" or "View Webhooks"
- Choose your target channel and copy the webhook URL
- Optionally customize the webhook's name and avatar (we'll override these in code)
The webhook URL looks like: https://discord.com/api/webhooks/123456789/abcdefghijklmnop
This is the URL we would send our POST request to:
$webhookUrl = 'https://discord.com/api/webhooks/123456789/abcdefghijklmnop';$payload = []; // we will later fill this arrayHttp::withHeaders(...) ->post($webhookUrl, $payload);
Critical note: Treat webhook URLs like...