Last active
August 31, 2016 21:19
-
-
Save kvendrik/0e84cc191a76769ff809ddaa200a755c to your computer and use it in GitHub Desktop.
Super Simple API Setup in Ruby + Curl Commands
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
| 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 |
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
| 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