cURL: API Debugging Made Easy
If you’re an avid programmer or even just familiar with your computer’s Bash terminal, odds are it’s come up before: the cURL command.
cURL stands for Client URL Request Library, and it allows you to use your terminal to send and request information from websites or APIs.
It’s useful for all kinds of different things, from downloads to installs to web scraping to data analysis. But one of it’s most common uses in programming is API requests.
There are other tools for this, of course, like Postman, but if you just need to do a quick check to see what happens when you try to access an endpoint, cURL is a fast and effective way to do it.
You can check if you have the cURL command line tool installed by typing
curl -V in your terminal. If you don’t, you can follow this tutorial to install it.
There are literally hundreds of options you can use with cURL — you can type
curl --help into your terminal to see the full list. But for accessing APIs, the ones you’ll be using the most are probably
If all you need to do is send a GET request to a URL (no special headers or anything), then using cURL is pretty simple. Just type
cURL [URL path].
For example, if you wanted to access the PokeApi, which gives you info on everything Pokemon, you could do the following to access information on the first item stored in the database:
If you try it, you’ll get back a whole bunch of JSON data on the Master Ball.
Many APIs are more complicated than that, though, which is where cURL’s options come in.
For example, if you wanted to submit a different type of request (POST or PATCH), for example, you’d include
-X POST or
-X PATCH (or
-X [whichever method you want to use]) in the command.
If you needed to specify a particular header, you’d include
-H "[header-name: header-info]". You can also use multiple headers as long as you put
-H before each one.
And if you needed to send some data, you’d include
PokeApi doesn’t require any of those things — it certainly won’t let you make changes to the database using request types other than GET — but here’s a version of the same request we made before using all three of these options, just to show you what the syntax looks like:
curl -X GET -H "Content-Type: application/json" -d "" https://pokeapi.co/api/v2/item/1
Note that we just left the
-d flag as a blank string, since we aren’t sending any data to the API. But if you did want to send data, you’d put it in that string.
That should be enough to get you started with cURL, but you can always check out the documentation to learn more about how it works and the different options available.
Just another useful tool in your arsenal!