REST Curl Helper
Join the DZone community and get the full member experience.
Join For Free// A small bash script that wraps around curl to help more easily test RESTful sites.
#!/bin/bash
AUTH="user:password"
BASE="http://localhost:3000"
METHOD=$1
DEST="$BASE$2"
XML=$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" \"ed ed@ed.com \""
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
REST
Web Protocols
Opinions expressed by DZone contributors are their own.
Comments