chop-dbhi / data-models-service

Service for consuming files in the data models format.
1 stars 1 forks source link

Add support for webhooks #16

Open bruth opened 8 years ago

bruth commented 8 years ago

The outcome of this feature is for consuming services to receive notification when a change in the data occurred. This will be implemented using webhooks which involves:

For simplicity, there will only be a single generic change event in this service for any change in the data models that occur. The mechanism for [un]subscribing webhooks will be a YAML file that will be persisted on disk. This should be suitable given the small scale. To ensure serializability of changes, subscriptions will be queued in a change that a worker will consume batching the changes and writing the file back to disk.

A service can subscribe themselves by sending PUT request to the /hooks/:secret endpoint. Where :secret should be a sufficiently complex string that cannot be guessed or have potential collisions. A good choice would be a random UUID. Subsequent PUT requests are idempotent and persisted.

PUT /hooks/a7c63bc1837a8d8d70e
Content-Type: application/json

{
    "url": "http://myserver.com/data-models",
    "events": ["change"]
}

Unsubscribing is simply sending a DELETE request to the same endpoint.

DELETE /hooks/a7c63bc1837a8d8d70e
Content-Type: application/json

Note, this requires the consumer to persist the secret key used in the URL so they can update or delete the hook later if necessary.