Skip to content

Instantly share code, notes, and snippets.

@sparrovv
Created October 21, 2010 21:01
Simple Ruby Web Servlet done with Webrick
# Example of simple webservlet, that can run on your computer and be triggered by http
require 'webrick'
class Simple < WEBrick::HTTPServlet::AbstractServlet
def do_GET(request, response)
status, content_type, body = do_some_stuff(request)
#system('touch ~/yeah.file')
response.status = status
response['Content-Type'] = content_type
response.body = body
end
def do_some_stuff(request)
return 200, "text/plain", "you got a page"
end
end
server = WEBrick::HTTPServer.new(:Port => 3333)
server.mount "/test", Simpte
# Enable shutdown on C-c
trap("INT"){ server.shutdown }
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment