Created
March 5, 2016 21:00
-
-
Save dmcnulla/94eea3cc1f806e380a47 to your computer and use it in GitHub Desktop.
This file contains 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
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