Friday, May 31, 2013

Copy as Curl

At work the other day I noticed something new in the Chrome browser developer console. Under the "History" tab, if you right click on a source you are presented with the following menu:

The menu item that intrigued me was "Copy as Curl". For those who are not Unix savvy, curl is a common utility that allows you to fetch a web page without using a browser. It is a very useful tool in web development. When I clicked on Copy as Curl, I pasted this into my terminal:

The command returned gibberish, but I noticed that it had the "Accept-Encoding: gzip,deflate,sdch"" header set, which means the content is compressed. By piping the results into gunzip (and then jsonpp) I was able to get the following:
Overall I thought it was a pretty cool feature. If you are still wondering why that output would be useful, it is because that output is extremely easy to parse from a programming perspective. You could use this to easily build a script that monitored the price for a specific laptop configuration for example.

Well made software provides solutions to needs we don't know about. I don't think I ever thought "I wish there was a way to make an identical request with curl", but now that I know about it, I will use it a ton.

1 comment:

  1. Rather than piping through gunzip, just use `curl --compressed` instead of plain `curl`.