Skip to content

Instantly share code, notes, and snippets.

@mamund
Created June 14, 2017 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamund/fe33324e2f1fbae5fe146bc59998fbcd to your computer and use it in GitHub Desktop.
Save mamund/fe33324e2f1fbae5fe146bc59998fbcd to your computer and use it in GitHub Desktop.
webhooks
// Initialize WebHooks module.
var WebHooks = require('node-webhooks')
var webHooks = new WebHooks({db: './webHooksDB.json'}) // json file that store webhook URLs
// sync instantation - add a new webhook called 'shortname1'
webHooks.add('shortname1', 'http://www.webapp.com/resources/shortname1').then(function(){
// done
}).catch(function(err){console.log(err)})
// add another webHook
webHooks.add('shortname2', 'http://www.webapp.com/resources/shortname2').then(function(){
// done
}).catch(function(err){console.log(err)});
// trigger a specific webHook
webHooks.trigger('shortname1', {data: 123})
webHooks.trigger('shortname2', {data: 123456}, {header: 'header'}) // payload will be sent as POST request with JSON body (Content-Type: application/json) and custom header
*** REQUEST
POST http://www.webapp.com/resources/shortname1
Content-Type : text/uri-list
http://client.example.org/listener
*** RESPONSE
201 Created
Location : http://www.webapp.com/resources/shortname1/1234
Link : <http://www.webapp.com/resources/shortname1>, rel="Subscriptions"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment