Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.