Skip to content

Instantly share code, notes, and snippets.

@nodebotanist
Last active November 12, 2016 20:05
Show Gist options
  • Save nodebotanist/9c55d6ce82aa0d1dec28540732d5f11a to your computer and use it in GitHub Desktop.
Save nodebotanist/9c55d6ce82aa0d1dec28540732d5f11a to your computer and use it in GitHub Desktop.

Serverless Architecture

About Me

  • @nodebotanist
  • technically a student (studying for BSE in EE @ Arizona State)
  • Developer Relations Engineer @ Auth0/Webtask IO
  • Gender Non-Binary (they/them)

What is serverless?

  • Why bother setting up an entire server just to run a webhook?
  • Wanna customize slack without learning the entire API in a weekend?
  • Want the ease of IFTTT but the power of Node.js?

Webtask.io

  • Run Node code without setting up a server
  • Have as little or as much control as you need
  • Supports 600+ npm modules
  • Custom slack slash commands with just a few clicks

The Webtask CLI

npm i -g wt-cli
wt init

more in the docs

The obligatory hello, world! example

module.exports = function(context, cb) {
    cb(null, { hello: context.data.name || 'Anonymous' });
}  

Full HTTP control

module.exports = function (context, req, res) {
    res.writeHead(200, { 'Content-Type': 'text/html '});
    res.end('<h1>Hello, world!</h1>');
}      

Using secrets

module.exports = function(ctx. cb){
    //common use: API keys for third-party services
    service.connect(ctx.secrets.myAPIKey);
}

wt create webtask.js --secret myAPIKey=doTHOhdeou8dhotedundh

Express

var app = new (require('express'))();
app.get('/', (req, res) => res.send('Hello World'));
module.exports = app;

Using Webtask for webhooks

  • Write your webtask, using ctx.query if it will take GET requests and ctx.body if the webhook will take POST requests
  • You'll get a URL when you deploy your webtask
  • point the service at that URL

Using westask slack commands

docs

  • Add the webtask app to your slack org
  • run /wt create [name] in any channel
  • you'll be pointed to the webtask editor to vrite your new commands

Having issues?

Open live-streaming logs using wt logs for the cli, they appear in the bottom pane of the web editor

Questions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment