Here’s a nifty one-liner to get the status code from an HTTP call.

The key is the -w / --write-out flag which accepts http_code as a valid parameter. This saves the trouble of a grep | sed pipe to get the http code from the standard header output.

# longform
curl --head --silent --output /dev/null --write-out "%{http_code}" http://localhost:8080/health

# shortform
curl -Is -o /dev/null -w "%{http_code}" http://localhost:8080/health