2 min read

Making Network Requests with Curl on macOS Tahoe

curl (Client URL) is a command-line tool for transferring data to or from a server. On macOS Tahoe, it is pre-installed and essential for testing APIs, downloading files, and debugging network issues.

Basic GET Requests

The simplest use of curl is to retrieve the content of a URL.

curl https://www.example.com

This prints the HTML source of the page to your terminal.

Downloading Files

To save the output to a file instead of printing it, use the -O (uppercase letter O) or -o (lowercase letter o) flags.

Save with Original Filename (-O)

This saves the file using the name specified in the URL.

curl -O https://example.com/image.png

Save with Custom Filename (-o)

This allows you to specify the output filename.

curl -o my_image.png https://example.com/image.png

Inspecting Headers

To view the HTTP headers returned by a server without downloading the body content, use the -I (Head) flag. This is useful for checking server status codes or content types.

curl -I https://www.google.com

Output Example:

HTTP/2 200
content-type: text/html; charset=ISO-8859-1
...

Sending Data (POST Requests)

curl is widely used for interacting with REST APIs. You can send data using the -d flag, which defaults the request method to POST.

curl -d "param1=value1&param2=value2" https://api.example.com/resource

Sending JSON Data

When working with modern APIs, you often need to send JSON and set the Content-Type header.

curl -H "Content-Type: application/json" \
     -d '{"username":"tahoe_user","active":true}' \
     https://api.example.com/users
  • -H: Adds a custom header.
  • -d: Sends the data payload.

Handling Redirects

By default, curl does not follow HTTP redirects (like 301 or 302). To follow redirects automatically, use the -L flag.

curl -L http://google.com

Verbose Mode

If a request is failing, use -v to see the complete handshake, headers sent, and headers received.

curl -v https://example.com

For more networking tools, refer to Networking Commands on macOS Tahoe.