Skip to content

Instantly share code, notes, and snippets.

@ampedandwired
Created September 9, 2012 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ampedandwired/3682627 to your computer and use it in GitHub Desktop.
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
#!/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