Last Updated: September 03, 2019
·
22.17K
· sativaware

Include HTTP headers in Curl response

If you are a developer - chances are you are familiar with and use curl on a daily basis - whether it's for testing or tooling.

Lets go over the case of testing a JSON API using curl — By default, curl will make a request to the url you provide and print out the response body. In this case we are making a call to a JSON api to review the JSON data.

$ curl http://api.wildspots.org/ping

#{"ping":"Response from Wildspots API"}%

From time to time - seeing the HTTP Headers & protocol information of a request is useful - often during initial setup of a web server or during testing.

To include HTTP Headers & protocol information - we simply use the -i option with the curl command.

$ curl -i http://api.wildspots.org/ping

# HTTP/1.1 200 OK
# Server: nginx/1.2.2
# Date: Sun, 19 Jan 2014 07:38:49 GMT
# Content-Type: application/json
# Transfer-Encoding: chunked
# Connection: keep-alive
# X-Powered-By: Express

# {"ping":"Response from Wildspots API"}%

The man page on curl describes the -i option as follows:

-i/--include
  (HTTP) Include the HTTP-header in the output. The HTTP-header  includes things like server-name, date of the document, HTTP-version and more...

References

curl man page

Wildspots.org API docs