Created
April 21, 2013 03:14
-
-
Save roder/5428312 to your computer and use it in GitHub Desktop.
quick and dirty function for JSON REST APIs for your shell.
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
function jurl() { | |
case `echo $1 | tr '[a-z]' '[A-Z]'` in | |
"PUT"|"POST") | |
curl -vs -H "Content-Type: application/json" -X $1 -d "${2}" $3 | python -mjson.tool | |
;; | |
"GET"|"DELETE") | |
curl -vs -H "Content-Type: application/json" -X $1 $2 | python -mjson.tool | |
;; | |
*) | |
echo "Error: Please use of the following HTTP methods: GET, POST, PUT, DELETE." | |
echo "PUT and POST must include a body (e.g.: jurl PUT '["hello, world!"]' http://exmaple.com/)." | |
echo "GET and DLETE do not require a body." | |
echo "jurl Parameters must be ordred as METHOD [BODY] URL." | |
;; | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment