Created
October 21, 2010 21:01
Simple Ruby Web Servlet done with Webrick
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
# 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