Skip to content

Commit

Permalink
Create a middleware to prettify JSON response.
Browse files Browse the repository at this point in the history
  • Loading branch information
nelstrom committed Feb 25, 2011
1 parent c6180be commit 6d940cd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/json_prettify_middleware.rb
@@ -0,0 +1,16 @@
require "json"

class JsonPrettifyMiddleware
def initialize(app)
@app = app
end

def call(env)
status, headers, response = @app.call(env)
if headers["Content-Type"].include? "application/json"
objects = JSON.parse response.first
response = JSON.pretty_generate(objects)
end
[status, headers, response]
end
end

0 comments on commit 6d940cd

Please sign in to comment.