Skip to content

Instantly share code, notes, and snippets.

@Juice10
Last active April 20, 2018 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juice10/c1b0d950fb1341b153ca6d83ad28bbba to your computer and use it in GitHub Desktop.
Save Juice10/c1b0d950fb1341b153ca6d83ad28bbba to your computer and use it in GitHub Desktop.
# Import Sinatra
require 'sinatra'
# Import Sinatra's JSON package needed for neat JSON responses.
require 'sinatra/json'
# setup port, ip address and environment
set :port, 8080
set :bind, '0.0.0.0'
set :environment, :production
# the /init endpoint to let OpenWhisk know our action works.
post '/init' do
'OK'
end
# /run gets invoked every time our action is called.
post '/run' do
# extract any parameters used when action was invoked
payload = begin
JSON.parse(request.body.read)
rescue StandardError
{}
end
# YOUR CODE HERE...
# invoke our own code below. Our example has a highly original hello world.
message = 'Hello World'
if payload && payload['value'] && payload['value']['name']
message = "Hello #{payload['value']['name']}!"
end
# Return a response to our serverless action.
json message: message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment