Call REST Web Service using Shell Script

Yes ! It's true. You can invoke or consume or call a Web Service from inside a Linux/Unix shell script. This is same as doing from java or php or .net client. Actually most simple to call or invoke a web service is through shell scripting.

Let’s consider a REST web service that adds two numbers. Also you need to pass a token (string or numeric) as a parameter (consider this as a example - do not think over it as a functionality )

Web Service
http://<Host Name>/jp-addws/svc/rs/Add/numbers/$num1/$num2
Parameters - token & userid Request
http://<Host Name>/jp-addws/svc/rs/Add/numbers/10/20?token=123&userid=789
Shell Script
echo "Invoking Addition service to add two numbers";
num1=10
num2=20
result=
result=$(curl -X GET -i -H
"
Accept: application/json" -H
"Content-Type: application/xml"
-d "token=123&userid=789"
http://<Host Name>/jp-addws/svc/rs/Add/numbers/$num1/$num2)
echo "###############"
echo "Got response from Phone service"
echo $result
exit

You May Also Enjoy

SOAP Vs REST

Web Services Features

Web Services Types


Dialogue & Discussion