This file contains hidden or 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
module['exports'] = function transformStream (hook) { | |
// If the hook is not currently streaming, | |
// the req has already been fully buffered, | |
// and can no longer be streamed! | |
if (!hook.streaming) { | |
return hook.res.end('No streaming request detected. \n\nTo test streaming data to this Hook try running this Curl command: \n\n echo "foo" | curl --header "content-type: application/octet-stream" --data-binary @- https://hook.io/Marak/examples-transformStream'); | |
} | |
hook.req.on('end', function(){ | |
hook.res.end(); | |
}); |
This file contains hidden or 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
module['exports'] = function inputSchema (hook, callback) { | |
// Responds back with incoming Hook parameters | |
hook.res.end(JSON.stringify(hook.params, true, 2)); | |
}; | |
// Specify an optional schema object | |
// This enables validation and defaults for Hook input | |
// For complete documentation on available schema types, | |
// see: http://github.com/mschema/mschema | |
module['exports'].schema = { | |
"name": { |
This file contains hidden or 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
// Access incoming HTTP request data | |
module['exports'] = function accessRequestData (hook) { | |
var params = hook.params; | |
// params contains all incoming request parameters, | |
// such as query string or form data. | |
// See http://hook.io/docs#data for more information | |
// Responds back with all incoming HTTP params | |
hook.res.write(JSON.stringify(hook.params, true, 2)); | |
hook.res.end(); | |
}; |
This file contains hidden or 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
module['exports'] = function simpleHttpRequest (hook) { | |
// npm modules available, see: http://hook.io/modules | |
var request = require('request'); | |
request.get('http://httpbin.org/ip', function(err, res, body){ | |
if (err) { | |
return hook.res.end(err.messsage); | |
} | |
hook.res.end(body); | |
}) | |
}; |
This file contains hidden or 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
// A simple hello world microservice | |
// Click "Deploy Service" to deploy this code | |
// Service will respond to HTTP requests with a string | |
module['exports'] = function helloWorld (hook) { | |
// hook.req is a Node.js http.IncomingMessage | |
var host = hook.req.host; | |
// hook.res is a Node.js httpServer.ServerResponse | |
// Respond to the request with a simple string | |
hook.res.end(host + ' says, "Hello world!"'); | |
}; |
This file contains hidden or 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
module['exports'] = function datastoreExample (hook) { | |
var res = hook.res, | |
req = hook.req, | |
store = hook.datastore; | |
store.set('mykey', { foo: "bar" }, function(err, result){ | |
if (err) { return res.end(err.message); } | |
store.get('mykey', function(err, result){ | |
if (err) { return res.end(err.message); } | |
res.end(JSON.stringify(result, true, 2)); | |
}); |
This file contains hidden or 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
module['exports'] = function (hook) { | |
hook.res.end('ended'); | |
}; | |
module['exports'].inputs = ['echo', 'echo', 'echo']; | |
module['exports'].outputs = ['echo', 'echo', 'echo']; |
This file contains hidden or 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
module['exports'] = function echo (hook) { | |
// Access Node.js HTTP Request and Response objects | |
var req = hook.req, | |
res = hook.res; | |
// Use NPM Modules | |
var faker = require('faker'); | |
res.write('<strong>BYE BILLY</strong> '); | |
res.write(req.headers["x-forwarded-for"] + '<br/>'); | |
res.end(faker.hacker.phrase()); | |
}; |
This file contains hidden or 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
// gateway hook for running microservices on hook.io in real-time without an account | |
// example of deploying a js file to the hook.io cloud from the command line using cURL | |
// cat echo.js | curl --data-urlencode source@- http://gateway.hook.io | |
module['exports'] = function gatewayHook (hook) { | |
var mschema = require('mschema'); | |
var params = hook.params; | |
var source = params.source; |
This file contains hidden or 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
module['exports'] = function badTimeOutHook (hook) { | |
hook.res.write('hello'); | |
// never calls hook.res.end() | |
}; |