A simple FastAPI-based webhook receiver that validates incoming webhook payloads and simulates notification processing.
This project simulates a webhook receiver endpoint that:
- Accepts POST requests with JSON payloads containing
id,event, andmetadatafields - Normalizes all keys to lowercase for consistent processing
- Validates required fields and returns appropriate error codes
- Logs received events to the console
- Calls a mock
notify()function that simulates sending notifications
The notify() function is a placeholder that would typically integrate with real notification services like Slack, Telegram, Email, or other automation systems in a production environment.
- Python 3.7+
- fastapi
- uvicorn
Install dependencies:
pip install fastapi uvicornStart the server with:
uvicorn webhook_server:app --reloadThe server will start on http://localhost:8000 by default.
curl -X POST http://localhost:8000/webhook \
-H "Content-Type: application/json" \
-d @test_payload.jsonhttp POST http://localhost:8000/webhook < test_payload.json{
"status": "success",
"message": "Webhook processed for event: order.created",
"event_id": "evt_123"
}2024-XX-XX XX:XX:XX - INFO - Received webhook event: order.created (id: evt_123)
2024-XX-XX XX:XX:XX - INFO - Metadata: {'user': 'demo_user', 'amount': 99}
Notification sent for event: order.created
- 400 Bad Request: Returned when required fields (
id,event,metadata) are missing - 422 Unprocessable Entity: Returned when the request body is not valid JSON
- 500 Internal Server Error: Returned for unexpected server errors
webhook-processor-demo/
├── webhook_server.py # FastAPI application
├── test_payload.json # Example webhook payload
└── README.md # This file