How to Make a Simple GET Request from the macOS Command Line
Introduction
Tools such as Postman are useful for exploring APIs, but you can also make HTTP requests directly from the command line. This is often quicker for simple requests and useful when working on a remote server or troubleshooting an application.
This guide shows how to make a basic HTTP GET request on macOS using curl. It also covers wget as an alternative and jq for formatting JSON responses.
The examples use the Rick and Morty API, which returns JSON from its REST endpoints.
Install Homebrew
Homebrew is a package manager for macOS that makes it easier to install command-line tools and other software.
If you do not already have Homebrew installed, run the following command in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The installer explains what it will do and pauses for confirmation before making changes. Follow any post-installation instructions it displays, especially those that add Homebrew to your shell's PATH.
Install jq and wget
curl is already included with macOS, so it does not need to be installed separately.
Use Homebrew to install jq and wget:
brew install jq wget
jq is a command-line JSON processor. It can format, filter, and transform JSON data. wget is an alternative tool for making HTTP requests and downloading files.
You can check that the tools are available with:
curl --versionjq --versionwget --version
Make a GET request with curl
curl makes a GET request by default when you provide it with a URL:
curl -sLS https://rickandmortyapi.com/api | jq .
The command has four parts:
curlmakes the HTTP request.-sLShides the progress meter (-s), follows redirects (-L), and still shows error messages (-S).|pipes curl's response intojq.jq .pretty-prints the JSON response. The period (.) tellsjqto output the complete response without filtering it.
The API returns the following JSON:
{"characters": "https://rickandmortyapi.com/api/character","locations": "https://rickandmortyapi.com/api/location","episodes": "https://rickandmortyapi.com/api/episode"}
The response body is the data returned by the server. It is also commonly called the payload.
Save the response to a file
If you want to save the response instead of displaying it in the terminal, redirect the output to a file:
curl -sLS https://rickandmortyapi.com/api | jq . > response.json
You can then inspect the saved response with:
cat response.json
Make a GET request with wget
The same request can be made with wget:
wget -qO- https://rickandmortyapi.com/api | jq .
The wget options work as follows:
-qenables quiet mode.-O-writes the response to standard output instead of saving it to a file. The hyphen tellswgetto use the terminal output stream.|pipes the response intojq.jq .pretty-prints the JSON response.
This produces the same output as the curl example:
{"characters": "https://rickandmortyapi.com/api/character","locations": "https://rickandmortyapi.com/api/location","episodes": "https://rickandmortyapi.com/api/episode"}
Without -O-, wget generally saves the response to a file instead of sending it to the terminal. That makes it useful when downloading files, while curl is often more convenient for inspecting API responses.
Conclusion
For simple API requests on macOS, curl is usually the most convenient option because it is already installed. wget is a useful alternative, especially when downloading files, while jq makes JSON responses easier to read and work with.
Once you are comfortable combining these tools with pipes, you can inspect API responses, extract specific fields, and troubleshoot web requests without opening a separate GUI application.
Want more like this?
Drop your email below and we'll keep you posted.