Curl Commands – Example

Curl command to fetch the response and HTTP status code

curl -s -w '%{http_code}' -X GET ${SERVICE_URL}

s flag denotes silent output and w flag denotes write out the http_code in the output data.

curl -s -w '%{http_code}' -X GET ',LCCN:93005405&format=json'

Sample output:

curl -s -w '%{http_code}' -X GET ',LCCN:93005405&format=json'
{"LCCN:93005405": {"bib_key": "LCCN:93005405", "preview": "noview", "thumbnail_url": "", "preview_url": "", "info_url": ""}, "ISBN:0201558025": {"bib_key": "ISBN:0201558025", "preview": "restricted", "thumbnail_url": "", "preview_url": "", "info_url": ""}}200

To fetch the HTTP header alone.

curl -I -X GET ',LCCN:93005405&format=json'

To print the CURL version information along with the response.

curl -v -X GET ',LCCN:93005405&format=json'

To extract out the HTTP status code

curl -I -s -X GET ',LCCN:93005405&format=json' | grep 'HTTP/1.1' | awk '{print $2}'