Skip to content

Instantly share code, notes, and snippets.

@kvendrik
Last active August 31, 2016 21:19
Show Gist options
  • Select an option

  • Save kvendrik/0e84cc191a76769ff809ddaa200a755c to your computer and use it in GitHub Desktop.

Select an option

Save kvendrik/0e84cc191a76769ff809ddaa200a755c to your computer and use it in GitHub Desktop.
Super Simple API Setup in Ruby + Curl Commands
require 'sinatra'
require 'json'
post '/' do
push = JSON.parse(request.body.read)
{ :body => push }.to_json
end
get '/:id?' do
content_type :json
{ :params => params }.to_json
end
echo POST / json string
curl -H "Content-Type: application/json" -X POST -d '{"username":"xxx","password":"xxx"}' localhost:4567
echo POST / data.json file
# http://unix.stackexchange.com/questions/144479/what-does-the-at-symbol-before-a-filename-mean-in-a-curl-command
curl -H "Content-Type: application/json" -X POST localhost:4567 -d @data.json
echo GET /:id
curl localhost:4567/451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment