How to Use Curl

Curl is a command-line program that makes network requests and prints what comes back. It is already on almost every Linux, macOS and Windows machine, which is why API documentation is written in it.

Last updated . How this page is checked.

The command

curl https://httpbin.org/get

Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.

What the flags do

FlagWhat it does
curl URLGET the URL and print the response body.
curl -i URLAlso print the status line and response headers.
curl -v URLPrint the whole conversation, for debugging.
curl -o file URLSave the body to a file.
curl -d data URLPOST data to the URL.

Step 1: check it is there

Open a terminal and ask for the version. The first line is the version number; the lists below it are the protocols and features your build supports. If the command is not found, install the curl package with your system's package manager. On Windows 10 and 11 it is built in as curl.exe.

curl --version

Step 2: make a request and read it

The general shape is curl [options] URL. With no options curl sends a GET and writes the response body to the screen, nothing more. That is deliberate, so the output can be piped into other tools, but it hides the status code. Add -i and the first line of output tells you whether the request succeeded: 200 is success, 3xx a redirect, 4xx a problem with your request, 5xx a problem on the server.

curl https://httpbin.org/get
curl -i https://httpbin.org/status/404

Step 3: send something

Three additions cover most API calls. -H adds a header, such as an API key or the format you want back. -d adds a body, which turns the request into a POST. -X names a different method when you need PUT, PATCH or DELETE. Long commands are split across lines with a trailing backslash.

curl https://httpbin.org/post \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"name":"Ada"}'

curl -X DELETE https://httpbin.org/delete

Step 4: when it does not work

-v is the tool. Lines starting with * are curl describing what it is doing: resolving, connecting, negotiating TLS. Lines starting with > are the request it sent, and < the response headers it received. Nearly every problem shows up in one of those three places. If curl prints an error like curl: (6), the number is an exit code: 6 is a hostname that did not resolve, 7 a refused connection, 28 a timeout, 60 a certificate that failed verification.

curl -v https://httpbin.org/get

Common mistakes

  • Quote your URLs. Characters such as & and ? mean something to the shell.
  • No output is not always failure. Redirects and 204 responses have empty bodies. Check with -i.
  • Commands copied from documentation are usually written for bash. They need adjusting for Windows cmd and PowerShell quoting.

Related curl examples

More under Reference

References

  • curl tutorial — The project's own walk-through, from a first request onwards.
  • Everything curl — The free book by curl's maintainers, covering the tool end to end.

These links leave api-tester.com, which is independent of the projects they point to.

FAQ

What is curl used for?

Curl transfers data to or from a server from the command line. It is most often used to call and test HTTP APIs, download files and debug network requests.

How do I run a curl command?

Open a terminal, type curl followed by a URL and press Enter. Curl sends a GET request and prints the response body.

How do I check if curl is installed?

Run curl --version. If curl is installed it prints its version, supported protocols and features.