Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

REST Curl Helper

DZone's Guide to

REST Curl Helper

·
Free Resource
// 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

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}