25/10/2026 00:03am

What Is a Webhook? Webhook vs API, with a Discord Example
#what is a webhook
#webhook vs api
#webhook url
#discord webhook
#webhook signature
#polling vs webhook
Imagine you ordered something online and you are waiting for it at home. One option is to walk out to the mailbox every 10 minutes. Almost every trip, the box is empty, but you still have to make the walk. The other option is to get on with your day and let the courier ring the bell when the parcel actually arrives.
Programs face the same choice every day. The first approach is called polling. The second is what people are really asking about when they search "discord webhook url" or "what is a webhook in simple terms". Today Superdev Academy walks through what a webhook is, how it differs from calling an API, how to post a message into Discord with a single command, and the three things beginners most often get wrong once they start receiving webhooks themselves.
Polling vs webhooks: keep asking, or wait to be told
Polling means your program calls another system's API over and over on a timer, say once a minute, asking "any new orders?" or "any new issues?". Most of the answers are "nothing yet", yet every request still costs work on both sides. And if the event happens a few seconds after your last check, you find out almost a full interval late.
A webhook flips the direction. You register a URL of yours with the other system once. From then on, whenever an event you care about happens, that system sends an HTTP request to your URL, carrying the details of the event. You do not ask anything.
Polling: You keep asking whether anything is new
Webhook: The other system calls your URL when something happens
GitHub says as much in its own documentation: webhooks take less effort and fewer resources than polling an API, and they give near real-time updates because they fire at the moment the event happens.
Webhook vs API: what is actually different?
This question shows up constantly in search, and the most accurate answer is that a webhook is not a rival to an API. It is the same kind of conversation, turned around.
When you call an API, you start the conversation: you send a request and wait for a response. (If that picture is still fuzzy, read What Is an API? first.) With a webhook, you are the one waiting, and the other system starts the conversation. Both use HTTP. The only difference is who presses send first.
So when should you use which? GitHub's guidance is clear: API calls suit occasional, one-off lookups from a small number of sources, while webhooks suit watching many things and needing to know as soon as something changes. In real projects the two usually work together. The webhook tells you something happened, and your program then calls the API to fetch the details.
How does a webhook work? It is one HTTP request
There is no magic hiding here. Take GitHub as the example. When an event you subscribed to happens, GitHub sends a POST to your URL with a JSON body (or form-urlencoded, if you chose that), plus headers that describe the delivery, such as:
X-GitHub-Event: which event this is, for examplepushorissuesX-GitHub-Delivery: a unique ID for this particular deliveryX-Hub-Signature-256: a signature that proves GitHub really sent it (more on this below)
GitHub also caps payloads at 25 MB. If an event would produce a bigger payload, it is simply not delivered.
"A webhook is an HTTP POST" is true almost all the time, but it is not a hard rule. The n8n Webhook node, for instance, accepts GET, POST, PUT, PATCH, DELETE and HEAD. If you want a refresher on what a request and a response are made of, we cover it in Handling HTTP Requests and Responses.
Try it: post a message to Discord with one curl command
The easiest webhook to get your hands on is Discord's incoming webhook. This time you are the sender and Discord is the receiver.
First, create a webhook in a Discord server where you are an admin. Following Discord's own guide: open Server Settings, go to the Integrations tab, click Create Webhook, choose the channel the messages should land in, then click Copy Webhook URL. You get a URL shaped like https://discord.com/api/webhooks/<id>/<token>.
Second, open a terminal and send a message with curl (if the terminal still feels unfamiliar, keep Essential Terminal Commands open alongside):
curl -X POST "https://discord.com/api/webhooks/<id>/<token>" \
-H "Content-Type: application/json" \
-d '{"content": "Deploy finished"}'What Discord's Execute Webhook documentation says, and what is worth knowing before you try:
The body needs at least one of
content,embeds,components,fileorpollcontentcan be up to 2000 charactersWithout
?wait=trueon the URL, the default is not to wait, and Discord replies204 No Content: success, with nothing in the bodyusernameandavatar_urloverride the sender's name and picture for that one message
We sent the same command to a URL with a made-up ID and token and got back a 404 with {"message": "Unknown Webhook", "code": 10015}. If you see that, either the URL is wrong or the webhook has been deleted.
One more thing to know: a Discord webhook only posts messages into a channel. If you want something that reads messages and replies inside Discord, you need a bot, which we cover in Build AI Multi-Agent Teams in Discord.
The receiving side: when GitHub or LINE calls you
On the receiving side, your job is to expose one URL on your server that is ready to accept requests, then paste that URL into the source system.
GitHub: in your repository's Settings, open Webhooks, click Add webhook, fill in the Payload URL, pick the events you want, and set a Secret for signature checks. A small tip from Discord's guide: to get GitHub commits into a Discord channel, take the Discord webhook URL, append /github, and use that as the Payload URL.
LINE: LINE's Messaging API documentation explains that when users interact with your LINE Official Account, the LINE Platform sends an HTTP POST with a webhook event object to the webhook URL you registered. That URL must use HTTPS, and every request carries an x-line-signature header you are expected to verify before processing.
If you have come across older tutorials that send alerts to LINE through LINE Notify, those no longer work. LINE announced that the LINE Notify service was terminated as of March 31, 2025, and points developers to the Messaging API instead.
A webhook URL is a secret: whoever has it can post
Notice that the curl command above has no API key and no password. Discord's documentation states plainly that webhooks do not require a bot user or authentication, because the token is already part of the URL. Anyone who gets hold of that URL can post anything into your channel as that webhook.
So treat a webhook URL exactly like an API key. Keep it in a .env file, never hard-code it, never commit it to GitHub, and never paste it into a group chat. We explain how to store it safely in What Is an API Key? How to Store API Keys in .env Safely. If one does leak, delete that webhook in Discord and create a new one; the old URL stops working.
Verify the signature before you trust it: X-Hub-Signature-256
The receiving side has the mirror-image problem. The URL you expose is public, so anyone can send a fake POST pretending to be GitHub. The fix is signature verification.
GitHub's documentation explains that when you set a Secret, GitHub computes an HMAC of the request body with SHA-256, using the Secret as the key, and sends the result in the X-Hub-Signature-256 header, which always starts with sha256=. Your side computes the same thing and compares. If they do not match, reject the request.
const crypto = require('crypto');
function isFromGitHub(rawBody, signature, secret) {
const expected = 'sha256=' +
crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
return signature.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
}We ran this function locally in Node.js and hit it with curl: a garbage signature got 401, a correctly computed one got 204. Two details matter. GitHub recommends a constant-time comparison such as crypto.timingSafeEqual instead of a plain ===, to guard against timing attacks. And the older X-Hub-Signature header, which uses SHA-1, exists only for legacy compatibility. LINE follows the same idea: HMAC-SHA256 with your channel secret, but Base64-encoded and sent in x-line-signature.
Reply fast, and expect duplicates
GitHub says your server should respond with a 2XX within 10 seconds. Take longer and GitHub terminates the connection and counts the delivery as failed. LINE recommends the same direction: process webhook events asynchronously. In plain terms: receive, verify the signature, reply 200, and do the heavy work afterwards.
The other thing beginners rarely expect is that deliveries can go missing and can also arrive twice. GitHub states that it does not automatically redeliver failed deliveries; if your server was down, you have to redeliver them yourself. On LINE, redelivery is turned off by default, and LINE does not disclose how many times or at what interval it retries.
So your receiving code should remember the IDs of events it has already processed and skip repeats. For GitHub, use X-GitHub-Delivery, which keeps its original value on a redelivery. For LINE, use webhookEventId, together with deliveryContext.isRedelivery.
Are webhooks always better than polling?
No, and it is worth being honest about that. Polling still makes sense when the source system offers no webhooks, when you only need data once in a while, or when your program runs somewhere without a public URL that anyone could call.
Webhooks are not perfectly reliable on their own either. If your server is down at the moment an event is sent, that event can quietly disappear. Systems that genuinely need accuracy therefore tend to use both: webhooks as the fast main channel, plus a small job that calls the API now and then to confirm nothing slipped through.
Summary: how is a webhook different from an API?
A webhook is an HTTP request another system sends to you when something happens; calling an API is you going to ask. Both use HTTP and usually carry JSON. The difference is direction. When you send, treat the webhook URL as a secret, just like an API key. When you receive, verify the signature before trusting anything, reply with a 2XX quickly, and always be ready for the same event to arrive twice.
The fastest way to make it click is to create a webhook in a Discord server of your own and send your first message with the curl command above. Once you see that message pop up in the channel, "webhook" stops being an abstract word.
Follow more articles and tips for people starting out as programmers on our channels.
Facebook: Superdev Academy Thailand (https://www.facebook.com/superdev.academy.th)
YouTube: Superdev Academy Channel (https://www.youtube.com/@SuperdevAcademy)
Instagram: @superdevacademy (https://www.instagram.com/superdevacademy/)
TikTok: @superdevacademy (https://www.tiktok.com/@superdevacademy?lang=th-TH)
FAQ: Frequently Asked Questions about This Article
A collection of questions and answers to help you better understand the content of this article.