Testing REST API Calls using Curl
Representational State Transfer (REST) was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. Fielding is one of the principal authors of the Hyper Text Transfer Protocol (HTTP) specification versions 1.0 and 1.1.
Since my current application is just a bunch of REST services, I needed to test these calls before publishing them. Unfortunately there were no good tools I could use to test these calls. I spent some time searching for scripts or apps that can make my life easier till I ran into this jewel somewhere on the web
You can just copy and paste this code into a file called apitest.sh and your good to go.
#!/bin/bash AUTH="user:password" BASE="http://example.com/" 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" \"<account><name>ed</name><email>ed@ed.com</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
Drupal theme by Kiwi Themes.









1 comment
Good stuff...did not know
Good stuff...did not know that you could execute CURL from the shell directly. Indeed good way to test.
-Jitendra
Post new comment