Skip to content

Instantly share code, notes, and snippets.

@roder
Created April 21, 2013 03:14
Show Gist options
  • Save roder/5428312 to your computer and use it in GitHub Desktop.
Save roder/5428312 to your computer and use it in GitHub Desktop.
quick and dirty function for JSON REST APIs for your shell.
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