Created
September 9, 2012 04:39
-
-
Save ampedandwired/3682627 to your computer and use it in GitHub Desktop.
A simple command line client for JSON (Rails) APIs - basically a curl wrapper
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
#!/bin/bash | |
baseurl='http://localhost:3000' | |
output_file=zb.out | |
rm $output_file | |
action=`echo $1 | tr '[a-z]' '[A-Z]'` | |
shift | |
url=$1.json | |
shift | |
while (( "$#" )); do | |
params="$params -d \"$1\"" | |
shift | |
done | |
cmd="curl -s -o $output_file -w \"%{http_code}\" -X $action $params $baseurl/$url" | |
echo $cmd | |
http_status=`eval $cmd` | |
echo HTTP status: $http_status | |
if [ -f $output_file ]; then | |
cat $output_file | python -mjson.tool 2> /dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment