Last active
December 20, 2015 16:29
-
-
Save straypacket/6162306 to your computer and use it in GitHub Desktop.
Sample Sinatra server
This file contains hidden or 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
## | |
# Call with: | |
# curl -i -H "Accept: application/json" "http://localhost:4567/?foo=1" | |
# or post with: | |
# curl -X POST -H "Accept: application/json" "http://localhost:4567/?foo=1" --data "foo=2" | |
## | |
require 'rubygems' | |
require 'sinatra' | |
require 'json' | |
encoding_options = { | |
:invalid => :replace, # Replace invalid byte sequences | |
:undef => :replace, # Replace anything not defined in ASCII | |
:replace => '', # Use a blank for those replacements | |
:universal_newline => true # Always break lines with \n | |
} | |
# Listen to all ports | |
set :bind, '0.0.0.0' | |
get '/' do | |
p params["foo"] | |
# Outputs 1 | |
end | |
post '/' do | |
p params["foo"] | |
# Outputs 2 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment