Skip to content

Instantly share code, notes, and snippets.

@jpablobr
Created June 2, 2011 23:59
Show Gist options
  • Save jpablobr/1005609 to your computer and use it in GitHub Desktop.
Save jpablobr/1005609 to your computer and use it in GitHub Desktop.
Curl REST API tester
#!/bin/bash
AUTH="user:password"
BASE="http://url.com/"
METHOD=$1
DEST="$BASE$2"
XML=$3
# or
# JSON=$3
# make sure args were passed
if [ $# -eq 0 ]; then
echo "usage: ./`basename $0` HTTP-METHOD DESTINATION_URI [XML]"
echo "example: ./`basename $0` POST "/accounts" \"<account><name>WHO</name><email>[email protected]</email></account>\""
exit 1
fi
# execute CURL call
curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' -w '\nHTTP STATUS: %{http_code}\nTIME: %{time_total}\n' \
-X $METHOD \
-d "$XML" \
-u "$AUTH" \
"$DEST"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment