Chrome Developer Tools have a very useful option that allows to copy any API request as a CURL command. This tool can be used to test APIs without having to rely on the Browser, get access to unofficial APIs, scrape data and many other useful scenarios. Please allow me to demonstrate.
In this video, I took the following steps:
- Navigate to weather.com
- Do an API look up by a zip code – 94404
- Copy resulting API call as CURL
- Confirm that I can repeat the same call in the terminal
- Modify the API to change zip code to 94121
- Perform another request in the terminal to confirm that I got the new data
To copy the API as CURL:
- Open Chrome Developer Tools
- Navigate to Network Tab
- Perform action that would trigger the desired API request
- Right click the desired API call
- Select “Copy” -> “Copy as CURL”
I find this technique extremely useful. For example, that is how I scraped hundreds of thousands of comments from Facebook in my post I Tried To Virtually Stalk Mark Zuckerberg.
Convert CURL request to a Programming Language
Another time, I had to reverse engineer a 3rd party analytics tool, so we could audit the data that we were sending into the tool. I figured out which API call the tool was using and converted the resulting CURL request (from Dev Tools) into Node.js using an online converter. Chances are there is a converter for your language of choice out there, Google it.
Finally, I created a Node binary app four our team to fetch and decode our events on a daily basis.
Those are some of my cooler use-cases, but I also use this tool weekly to help debug various bugs and to test how our API would perform under different scenarios.
How to copy network requests as cURL commands: https://t.co/x79824mnnf
— Chrome DevTools (@ChromeDevTools) December 30, 2017
Can you think of any other cool use cases? Please let me know in the comment area bellow.