Repository

Looks good to me!

User Tools

Site Tools


kb:tools:webhooks

A quick introduction to webhooks.

Several methods exist to synchronize data between services:

  1. Pull all data periodically then deconflict locally
  2. Allow server to notify your program of changes
  3. Pull only changed data from server

The first is the easiest, but wastes the most bandwidth and compute resources. The second is possible, but there may be intermittent issues, e.g. server gives up after a set number of failures, resulting in missed updates. The last is possible, requires the server itself to collect changes, but we can ensure the service will be ready for data queried from the server.

In the context of Google API, this corresponds to:

Setting up a webhook server is straightforward, this example in Python:

import flask
from flask import request, Response

app = flask.Flask(__name__)

@app.route("/webhook", methods=["POST"])
def webhook():
    print(request.json)
    return Response(
        "Success!\n",
        headers={"X-Goog-Channel-ID": 1,},
        status=200,
        mimetype="text/plain",
    )

app.run(host="localhost", port=8182, debug=True)

and then of course the venerable reverse proxy to pipe to the HTTP(S) port. Testing can be done with curl or other tools of choice, e.g. Postman.

kb/tools/webhooks.txt · Last modified: 18 months ago ( 2 May 2023) by 127.0.0.1