cURL is a command line tool that can be used, among other things, to make HTTP requests. Its basic syntax is:
When we execute this command, we get the raw response to the http request in the command line.
If you want a better and deeper insight on this cURL command, I recommend you take a look at its
man page. Here, I’m just going to talk about the options that I use to test APIs and find most useful.
The first option I’d like to talk about is
-I. It reduces the response to headers.
Another important option is
-H. It allows us to add request headers, like Content-Type, accept headers, api-key and so on. Here you have an example of a cURL request to a server, where we want to get a json response from the version 3 of the API using a client key:
Once we have set the right headers, it’s quite straight forward to execute actions over REST resources. In the next lines, I’ll omit the headers in order to improve readability.
To finish this post, I’d like to leave a link to a tool that I really like: the Chrome plugin Postman - REST client. It’s perfect for those who are not command line friends and/or are looking for a nice interface to make requests to their APIs.