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 echoHttp (hook) { | |
if (!hook.streaming) { | |
return hook.res.end('No streaming request detected.'); | |
} | |
hook.req.on('end', function(){ | |
hook.res.end(); | |
}); | |
hook.req.on('data', function(chunk){ | |
hook.res.write(chunk.toString()) |
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; | |
console.log('incoming', hook.req.url); | |
// 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 highFive(hook) { | |
// hook.io has a range of node modules available - see | |
// https://hook.io/modules. | |
// We use request (https://www.npmjs.com/package/request) for an easy way to | |
// make the HTTP request. | |
var request = require('request'); | |
// The parameters passed in via the slash command POST request. | |
var params = hook.params; |
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 faker (hook) { | |
var faker = require('faker'); | |
var params = hook.params; | |
var parts = params.property.split('.'); | |
faker.locale = hook.params.locale; | |
var result = faker[parts[0]][parts[1]](); | |
hook.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
// 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
// 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
// Simple microservice for generating fake data | |
// faker.js docs - http://github.com/marak/faker.js | |
module['exports'] = function fakeData (hook) { | |
var faker = require('faker'); | |
// supports multiple locales | |
faker.locale = 'en'; // try: 'de', 'es' | |
// supports all faker.js methods | |
var result = faker.name.findName(); | |
hook.res.end(result); | |
}; |
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 imageResize (hook, callback) { | |
// GraphicsMagick fully supported | |
var gm = require('gm'); | |
// for a more complete example that supports file uploads and streaming uploads | |
// see: http://image.resize.hook.io | |
// grab an image as a url | |
// no file has been uploaded, fallback to the image "url" parameter | |
var stream = hook.open('https://hook.io/img/robotcat.png'); | |
hook.res.writeHead(200, { 'Content-Type': 'image/png' }); | |
gm(stream) |
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 mergeStreams (hook) { | |
var ms = require('merge-stream'); | |
var stream1 = hook.open('https://hook.io/Marak/examples-helloWorld'); | |
var stream2 = hook.open('https://hook.io/Marak/examples-helloWorld'); | |
var merged = ms(stream1, stream2); | |
// You can also add new streams later | |
// merged.add(stream3); | |
merged.on('data', function(chunk){ | |
hook.res.write(chunk.toString()); | |
}); |
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
// Connect two Hooks together using .pipe() | |
module['exports'] = function pipeHook (hook) { | |
// hook.open will create a stream to the echo hook | |
// hook.open is for convience. Any stream will work. | |
var stream = hook.open('https://hook.io/Marak/examples-helloWorld'); | |
// Once we have created a stream to helloWorld, | |
// pipe that stream to the client. | |
// This techinque can be used on any streaming interace | |
stream.pipe(hook.res); | |
}; |