The focus is on these technology patterns:
- WebHooks are a REST-based call between web servers. One web server has an event, and data, that it distributes to client servers.
- REST Hooks is a pattern promoted by Zapier, and is an API for distributing WebHooks, while allowing a client server to selectively subscribe/unsubscribe to events using an API
In both WebHooks and REST Hooks, a web service has an event and data, and is distributing the event to other web services which subscribe to the event. For example, a payment processing platform would notify an eCommerce site about sales via a WebHook or REST Hook. Another example is GitHub, which has several WebHooks it can invoke to notify certain lifecycle events in a GitHub repository.
The difference is how the client service subscribes to the events.
In the WebHook scenario, an event subscribtion is made manually. The human making the subscription will use some kind of Web UI, such as the administrative area of a web service, to select an event, and configure the subscription to the event. Part of that configuration is a URL that is to be invoked to handle the event.
Documentation: http://resthooks.org/
This is a pattern suggested by Zapier to improve on the WebHooks model.
The client service has five API's it can call:
GET /path/to/endpoint
- Retrieve the events that can be subscribed, and the current subscriptionsPOST /path/to/endpoint
- Subscribe to an event described in JSON in the bodyGET /path/to/endpoint/:id
- Retrieve data about a specific subscriptionPUT /path/to/endpoint/:id
- Modify a subscriptionDELETE /path/to/endpoint/:id
- Delete a subscription
This repository contains two web services written in TypeScript, and running on top of ExpressJS on Node.js.
The receiver
directory contains a client service that handles some WebHook and REST Hook subscriptions.
The sender
directory contains a service that distributes events with both the WebHook and REST Hook model.
In both:
npm install
-- Install dependenciesnpm run build
-- Build the TypeScript into JavaScriptnpm run watch
-- Dynamically watch source code, automatically rebuilding TypeScript into JavaScriptnpm run monitor
-- Dynamically watch built code, keep the server running, restarting the server when code is rebuilt