Mastodon hachyterm.io

Postman or Insomnia are popular GUI tools to explore and create HTTP requests for working with APIs.

But did you know that you can use a simpler and still powerful alternative on the terminal?

Of course, I’m talking about curl!
Or in my case, rather curlie, the “interface of HTTPie with the features of curl”.

To be fair, Postman and Insomnia offer more features like automated testing, workspaces, designing & mocking interfaces, etc.

But these are not features I regularly use. I need to make API requests, and for that the terminal suffices.

Install curl/curlie

For Arch Linux:

yay -S curlie

Or other ways.

Install jq

jq is a command-line JSON parser. It’s useful for formatting json, one of the most common formats for API data.

yay -S jq

Usage

Synopsis of curlie:

curlie [CURL_OPTIONS...] [METHOD] URL [ITEM [ITEM]]

You can pipe the output of curlie to other commands:

curlie -v https://api.spacexdata.com/v3/launches/ | jq -C | less -R

Here we do a GET request to the SpaceX API. We pipe the output to jq -C to pretty print the json response with terminal colors.
Then we use a pager to get the output one “page” at the time, because it’s quite a lot of data.

More JSON on the Command Line

This guide by George Ornbo will show you how to use jq in detail: JSON on the command line with jq.