Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Webhooks do's and dont's

Webhooks do's and dont's

As modern applications are becoming more and more a composite of APIs and the serverless architectures are getting more attention, API providers can’t afford any longer to expose only traditional REST endpoints.

When it comes to designing webhooks there is nothing really close to a standard in the HTTP API literacy. Every service implements webhook differently leading to many different flavors of webhooks implementations out there.

After integrating APIs from more than 100 different services I can tell that the way a service exposes webhooks can be a deal breaker. So here are the things that make us happy when we need to integrate with a service exposing webhooks.

Avatar for Giuliano Iacobelli

Giuliano Iacobelli

September 27, 2017

Other Decks in Technology

Transcript

  1. [email protected] Lego for APIs Stamplay is a low-code platform that

    provides a visual interface to drag&drop connectors and creates integration workflows between services
  2. [email protected] Token based Auth
 (e.g OAuth2) Machine readable docs (OpenAPI,

    RAML, IO docs) Webhooks HATEOAS Requirements for APIs in the automation era Simple, consistent, flexible, friendly, explorable via URL 
 and use web standards where they make sense.
  3. [email protected] Requirements for APIs in the automation era Simple, consistent,

    flexible, friendly, explorable via URL 
 and use web standards where they make sense. Token based Auth
 (e.g OAuth2) Machine readable docs (OpenAPI, RAML, IO docs) Webhooks HATEOAS
  4. [email protected] Consumer sets up a server to listen for webhooks


    Consumer registers webhook URL with provider
 Provider starts making request to webhook URL when event happens Webhook Setup
  5. [email protected] Consumer sets up a server to listen for webhooks


    Consumer registers webhook URL with provider
 Provider starts making request to webhook URL when event happens Webhook Setup
  6. [email protected] Consumer sets up a server to listen for webhooks


    Consumer registers webhook URL with provider
 Provider starts making request to webhook URL when event happens Webhook Setup
  7. [email protected] Webhook anatomy Webhooks are fundamental pieces of an API

    today and a simple notification is no longer enough, as an API provider you need to do the heavy lifting for your users • a verb: POST • an explicit event type: which could be subscribed by any user (for Github: pull_request, fork, commit, issues, etc.. ) • a payload: containing the relevant data for the related event 
 • including: the resource itself, the sender (user who triggered the webhook) 
 • constant data structure • a security hash: to ensure webhook was delivered by the rightful authority 
 • for Github: sharing a common secret used to generate a hash from the payload • an ID
  8. [email protected] Fat payload vs Thin payload Provide as much information

    as possible about the event that is being notified, as well as additional information for the client to act upon that event.
  9. [email protected] Batch vs single Services providing high frequency / volume

    of data might opt to make less calls and batch data into an array
  10. [email protected] Subscribing to events using multiple URLs Some services route

    the same type of notification (topic) to more than one URL
  11. [email protected] API for Webhooks aka REST Hooks Webhooks shuold be

    able to be configure programmatically, and guess what? You can build an API for that.
  12. [email protected] Topics / Event types Mailchimp’s webhooks are strongly tied

    to lists so they have 
 implicit notion of the resource they are tied to
  13. [email protected] Topics / Event types Cisco Spark threat webhooks as

    a standalone resource, with it’s own set of CRUD methods. Subscription to topic must include resource and event type.
  14. [email protected] Fine-grained topics vs Fine-grained resource watch Decide whether you

    want to have customer subscribe for events on each single specific resource or to subscribe by type of resource.
  15. [email protected] Renewing subscriptions Avoid sending webhooks to endpoints that are

    no longer active by implementing a subscription renewal logic
  16. [email protected] Renewing subscriptions Avoid sending webhooks to endpoints that are

    no longer active by implementing a subscription renewal logic
  17. [email protected] Renewing subscriptions Avoid sending webhooks to endpoints that are

    no longer active by implementing a subscription renewal logic Three days..
  18. [email protected] Renewing subscriptions Avoid sending webhooks to endpoints that are

    no longer active by implementing a subscription renewal logic
  19. [email protected] Securing Webhooks The service shall provide a way to

    validate that they were not sent by an untrusted third- party. At least a lightweight static shared secret is a good start.
  20. [email protected] Securing Webhooks More secure strategies include hash signature of

    the JSON notification. The digest is then sent using a dedicated header and can be verified by the receiving webhook. Client Server Create subscription + secret Notification + Additional header with hash signature of the JSON notification
  21. [email protected] Receives HTTP requests and captures the data for later

    inspection Secure introspectable tunnels to localhost Webhooks toolkit Some must-have tools when working with webhooks