Curl GET Request Example

GET is what curl does when you give it nothing but a URL. The interesting parts are everything around it: building a query string safely, seeing the status line, and keeping the output clean enough to pipe.

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
-iPrint the response status line and headers before the body.
-sSilent: no progress meter. Pair with -S so errors still show.
-GSend any -d data as a query string instead of a body.
-o fileWrite the body to a file instead of the terminal.
-w formatPrint extra facts after the transfer, such as %{http_code}.

Adding query parameters

You can type the query string straight into the URL, but then the escaping is your job: a space, an ampersand or a non-ASCII character in a value silently changes what the server receives. Let curl encode values instead. -G moves -d data into the URL, and --data-urlencode percent-encodes each value.

Always quote the URL. In most shells an unquoted & ends the command and runs the rest in the background, and ? can be treated as a filename wildcard.

curl -G https://httpbin.org/get \
  --data-urlencode "q=rate limit & retries" \
  --data-urlencode "page=2"

# same request, encoded by hand
curl "https://httpbin.org/get?q=rate%20limit%20%26%20retries&page=2"

Seeing more than the body

By default curl prints only the response body, which hides the two things you usually need when a request misbehaves: the status code and the headers. -i prints them above the body, -v adds the request curl sent, and -w extracts single values for scripts.

curl -i https://httpbin.org/get                # headers + body
curl -s -o /dev/null -w "%{http_code}\n" https://httpbin.org/get   # status only
curl -sS https://httpbin.org/get -o response.json            # save, stay quiet

Common mistakes

  • Do not add -X GET. GET is already the default, and -X also overrides the method curl would pick after a redirect.
  • A GET with -d becomes a POST unless you also pass -G.
  • An HTTP error is not a curl error. A 404 still exits with code 0. Use -f when a script needs a non-zero exit on 4xx and 5xx.

Related curl examples

More under Methods

References

  • curl man page: -G — The flag that turns -d data into a query string.
  • MDN: GET — What the method means and what a server may do with it.

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

FAQ

How do I send a GET request with curl?

Run curl followed by the URL, for example curl https://httpbin.org/get. GET is the default method, so no extra flag is needed.

How do I pass query parameters in a curl GET request?

Either put them in the quoted URL, or use -G with one --data-urlencode "name=value" per parameter so curl builds and percent-encodes the query string for you.

How do I see the response headers of a GET request?

Add -i to print the status line and headers above the body, or -v to also see the request curl sent.