Skip to content

Instantly share code, notes, and snippets.

@mensfeld
Created January 10, 2019 09:11
Show Gist options
  • Save mensfeld/7af5b24a404432738e3adf821b94f344 to your computer and use it in GitHub Desktop.
Save mensfeld/7af5b24a404432738e3adf821b94f344 to your computer and use it in GitHub Desktop.
require 'webrick'
require 'set'
server = WEBrick::HTTPServer.new(Port: 3000)
set = Set.new
server.mount_proc '/' do |req, res|
data, action = req.body.split(',')
action ||= 'ADD'
# Return set data for any command, no need to handle GET
case action
when 'ADD'
set.add(data)
when 'DEL'
set.delete(data)
end
res.body = set.to_a.to_s
end
trap('INT') { server.shutdown }
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment