A webhook registration endpoint lets other apps tell your app where to send event updates automatically.
Webhook registration endpoint in Rest API
POST /webhook/register
Content-Type: application/json
{
"url": "https://example.com/my-webhook",
"event": "order_created"
}The endpoint usually accepts a POST request with JSON data.
The JSON includes the URL to send events to and the event type to listen for.
POST /webhook/register
{
"url": "https://myapp.com/hook",
"event": "user_signed_up"
}POST /webhook/register
{
"url": "https://myapp.com/hook",
"event": "payment_received"
}This simple Flask app creates a webhook registration endpoint at /webhook/register. It accepts POST requests with JSON containing url and event. It saves the webhook info in a list and returns a confirmation message.
from flask import Flask, request, jsonify app = Flask(__name__) # Store registered webhooks in memory for demo registered_webhooks = [] @app.route('/webhook/register', methods=['POST']) def register_webhook(): data = request.get_json() url = data.get('url') event = data.get('event') if not url or not event: return jsonify({'error': 'Missing url or event'}), 400 # Save the webhook info registered_webhooks.append({'url': url, 'event': event}) return jsonify({'message': f'Webhook registered for event {event} at {url}'}), 201 if __name__ == '__main__': app.run(debug=True)
In real apps, store webhook info in a database, not just memory.
Always validate the URL to avoid security risks.
Consider sending a test event to the webhook URL to confirm it works.
A webhook registration endpoint lets other apps tell you where to send event updates.
It usually accepts a POST request with JSON containing the URL and event type.
Store the webhook info safely and confirm registration with a response.