Skip to content

Instantly share code, notes, and snippets.

@cheald
Created September 14, 2012 02:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cheald/3719513 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rack'
require 'json'
Rack::Handler::Thin.run proc{ |env|
req = Rack::Request.new(env)
begin
json = JSON.parse(req.body.read)
[200, {"Content-Type" => "text/plain"}, json.inspect]
rescue JSON::ParserError
[400, {"Content-Type" => "text/plain"}, "Uh oh, your JSON didn't parse"]
end
}, :Port => 9292
% curl -i -X POST -d '{"screencast":{"subject":"tools"}}' http://localhost:9292/
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: close
Server: thin 1.4.1 codename Chromeo
{"screencast"=>{"subject"=>"tools"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment