
Webhooks
What is a Webhook?
A Webhook is a way for one application to automatically send information to another application when something happens.
Instead of continuously asking a server whether something has changed, the application simply waits for an event and receives a notification when it happens.
Simple Example
Imagine you ordered something online.
Instead of repeatedly asking:
"Has my order been delivered?"
your delivery company automatically sends you a notification when the order is delivered.
That notification is similar to how a webhook works.
How Does a Webhook Work?
A webhook usually follows these steps:
- Event happens — for example, a payment is completed.
- Service detects the event.
- Service sends an HTTP request to a URL provided by another application.
- The receiving application processes the data.
- A response is returned to confirm that the request was received.
For example:
Payment Service
↓
Payment Completed
↓
Webhook Request
↓
Your Server
↓
Process Payment

Webhook vs API
They may look similar, but their purpose is different.
| API | Webhook |
|---|---|
| You request information | Information is pushed to you |
| Client starts communication | Event starts communication |
| Usually request → response | Usually event → HTTP request |
| Good for fetching data | Good for receiving real-time events |
Example
With an API:
"Give me the latest payment status."
With a webhook:
"Tell me automatically when a payment is completed."
Webhooks in FastAPI
FastAPI can create an endpoint that receives webhook requests.
from fastapi import FastAPI, Request
app = FastAPI()
@app.post("/webhook")
async def webhook(request: Request):
data = await request.json()
print(data)
return {"status": "received"}
When another service sends a POST request to /webhook, FastAPI receives the data and processes it.
For example, the incoming data might look like:
{
"event": "payment_success",
"amount": 500,
"user": "charan"
}
Your FastAPI application can then perform an action such as updating a database, sending an email, or creating an order.
Where Are Webhooks Used?
Webhooks are commonly used for:
- Payment notifications
- Order and delivery updates
- Authentication events
- Messaging systems
- CI/CD pipelines
- Email events
- E-commerce applications
- Real-time notifications
- Connecting different applications
Important Security
A webhook endpoint is exposed to the internet, so you should not blindly trust incoming requests.
Professional webhook systems commonly use:
- Signature verification to confirm the request came from the expected service
- HTTPS to protect data during transmission
- Authentication or secret tokens
- Input validation
- Idempotency to prevent processing the same event twice
- Logging and monitoring for failed requests
Webhook in One Sentence
A webhook is an event-based HTTP callback where one application automatically sends data to another application when a specific event occurs.
Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments