Using cURL for API requests
When building APIs, you need a way to send requests to test out what you are building. For big projects, tools like Postman or Insomnia are a great choice because they offer much more than just a way to send requests.
However, for small projects where all you need is a way to send requests to test your API, I find using cURL much more convenient.
GET and DELETE
If not specified differently, default HTTP method is GET.
To specify HTTP method, use
POST, PUT and PATCH
For sending requests with data, use
If you are using
-d flag, request is by default treated as POST request, so you can omit
Other useful configuration
When using query parameters, wrap the url in
"" to avoid potential problems.
To send request headers use
Reading response status and headers
To see information such as response status and response headers, use
When things gets messy
When you need to send a request with multiple headers and a long url, it can quickly become a burden to type everything. You can easily end up with something like this:
To avoid that, I recommend using a cli tool like endpoint.