midwire
7/10/2014 - 2:00 PM

Use curl for REST testing APIs

Use curl for REST testing APIs

#!/usr/bin/env bash
# Use curl for REST testing apis
#
# curl params:
# i – show response headers
# H – pass request headers to the resource
# X – pass a HTTP method name
# d – pass in parameters enclosed in quotes; multiple parameters are separated by ‘&’

#     curl -i -H "Accept: application/json" -X POST -d "firstName=james" http://192.168.0.165/persons/person

ACCEPT="application/json"
METHOD=`echo $1| tr [a-z] [A-Z]`
URL=$2

curl -i -H "Accept: ${ACCEPT}" -X $METHOD "${URL}"