I wanted to test out the HTTP response codes from a number of our API endpoints. There is numerous ways to approach this but I thought it would be fun to use the command line and it turned out pretty straight forward.
First off I created a file with some urls in e.g.
1 2 3 |
|
And ran the following command:
1
|
|
This takes each line (url) and passes the argument to curl before outputting the url and http response code for said url into a file called responses.txt
1 2 3 |
|
You can then grep to count the number of different http response codes e.g.
1 2 |
|
In reality I ran the following command as wanted to do something a bit more complicated with curl by specifying certs and custom headers
1
|
|
I’m not suggesting this is the best way to do this but nice not to need any frameworks or libraries. If I want to do this more regularly I will probably use a cucumber feature and setup a job in our CI environment not, forgetting a nice looking report but for now this is fine.