Skip to content

Instantly share code, notes, and snippets.

@oisin
Last active Aug 29, 2015
Embed
What would you like to do?
HTTP Server that will print the JSON arriving from a client.
Simple server which just formats and prints JSON requests.
# Run this with
# rackup -s thin
#
# or if you are using bundler
#
# bundle exec rackup -s thin
#
# starts on port 9292
#
require 'json'
require 'awesome_print'
run lambda { |env|
request = Rack::Request.new(env)
if request.media_type == "application/json" and (body = request.body.read).length.nonzero?
ap JSON.parse(body), { indent: 2 }
end
[200, {"Content-Type" => "application/json"}, []]
}
# Kick off with
#
# bundle install
#
# to install the gems.
#
# Uses the thin webserver and awesome_print, which will format
# the output
source 'https://rubygems.org'
gem 'thin'
gem 'awesome_print'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment