Skip to content

Instantly share code, notes, and snippets.

@dmcnulla
Created March 5, 2016 21:00
Show Gist options
  • Save dmcnulla/94eea3cc1f806e380a47 to your computer and use it in GitHub Desktop.
Save dmcnulla/94eea3cc1f806e380a47 to your computer and use it in GitHub Desktop.
require 'webrick'
require 'json'
include WEBrick
def start_webrick(config = {})
config.update(:Port => 9001)
server = HTTPServer.new(config)
yield server if block_given?
['INT', 'TERM'].each {|signal|
trap(signal) {server.shutdown}
}
server.start
end
class RestServlet < HTTPServlet::AbstractServlet
def do_GET(req,resp)
puts "path is '#{req.path}'"
resp.body = '{"customer": "Invalid"}'
resp.status = 200
end
def do_POST(req,resp)
puts "path is '#{req.path}'"
puts "body is '#{req.body}'"
resp.body = '{"customer": "Invalid"}'
resp.status = 200
end
end
start_webrick { | server |
server.mount('/', RestServlet)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment