HTTP Server that will print the JSON arriving from a client.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Simple server which just formats and prints JSON requests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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"}, []] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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