This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74cd8e6
commit a55f11c
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
!SLIDE bullets incremental | ||
|
||
# Use cases | ||
|
||
* Realtime applications | ||
* Web crawlers/scrapers | ||
* Proxy servers | ||
* Bridging the client/server gap | ||
|
||
!SLIDE | ||
|
||
# Code please! | ||
|
||
!SLIDE smaller | ||
|
||
## webhooks.js | ||
|
||
@@@javascript | ||
// Require module from node-core | ||
var http = require("http"); | ||
|
||
// Attach function to the exports object | ||
exports.deliver = function(options, payload, callback) { | ||
|
||
// Create a new http request | ||
var req = http.request(options, function(res) { | ||
var body = ''; | ||
res.setEncoding('utf8'); | ||
|
||
// Capture the response body | ||
res.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
|
||
res.on('end', function() { | ||
// Return the result to the caller | ||
callback(body); | ||
}); | ||
}); | ||
|
||
// Send the payload to the endpoint | ||
req.write(payload); | ||
req.end(); | ||
}; | ||
|
||
!SLIDE smaller | ||
|
||
## application.js | ||
|
||
@@@javascript | ||
// Use a relative require to load the module | ||
var webhooks = require("./webhooks"); | ||
|
||
// Create a payload and options | ||
var payload = { | ||
name: "hecticjeff", | ||
webscale: true | ||
}, | ||
options = { | ||
host: "hecticjeff.net", | ||
port: 80, | ||
path: "/notify", | ||
method: 'POST' | ||
}; | ||
|
||
// Use the deliver method that we exported | ||
webhooks.deliver(options, payload, function(response) { | ||
console.log("Webhook responded with %s", response); | ||
}); |