Skip to content

Instantly share code, notes, and snippets.

@raws
Created November 16, 2010 15:52
Show Gist options
  • Save raws/701962 to your computer and use it in GitHub Desktop.
Save raws/701962 to your computer and use it in GitHub Desktop.
require "rubygems"
require "sinatra"
require "json"
class Jsonify
def initialize(app)
@app = app
end
def call(env)
status, headers, response = @app.call(env)
response = response.to_json
headers["Content-Length"] = response.length.to_s
headers["Content-Type"] = "application/json"
[status, headers, response]
end
end
use Jsonify
get "/foo" do
{ "foo" => "bar", "baz" => [ "blat", "honk", "hork" ] }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment