Created
June 14, 2017 09:06
-
-
Save mamund/fe33324e2f1fbae5fe146bc59998fbcd to your computer and use it in GitHub Desktop.
webhooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** 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