cURL is a command line tool that allows you to exchange information across nearly any point on the Web. If you've read API documentation before, you've probably seen cURL requests used to test APIs. cURL is powerful, ubiquitous, and open source, so it's a fundamental tool for your software development toolbox. There are many other API testing tools, like Postman and wget, but cURL has stayed around since the late 90s for a good reason, and if you're new to web development, it's a great way to learn to think like a web developer.
cURL has a bit of a learning curve, partly because it lives in the terminal and doesn't show output when you execute a command (tip: use `-v` for verbose output in cURL), partly because its documentation is a little technical. The best way to get comfortable with cURL is doing a few small operations with it first. Try these!
In the last example, take a close look at cURL's verbose output. We see a GET request to `https://www.abstractapi.com/`, a received 1256-byte response, and the status code `200`, which indicates our request has succeeded! If you run this request as `curl -v www.examplefail.com`, you receive a failed GET message. What does this mean?
A GET operation is one of the cornerstones of REST API operations, which standardizes the HTTP communication between web services. Instead of existing on one database, as they did in the 'monolithic' era of software development, applications now exist across databases and communicate with HTTP via Application Programming Interfaces (APIs). APIs act like switchboards that authenticate and route traffic. cURL is extremely useful in quickly testing these endpoints. Here's how we perform five basic API tests in cURL, and what the operation does.
We're using JSON Placeholder to test their API endpoints. Thanks for this great resource!
Consider the power contained in the simple operations we just performed: we sent, received, and changed data in a far away server. Imagine you're building an application and need an up-to-date geographic location: call the IP Geolocation API using cURL for an up-to-date weather report. Or maybe you need a stock report. Perhaps movie times? cURL opens the world of APIs and web development to everyone, and though its website might look old, it's here to stay. Happy travels.