Terminus by Warp
Show Curl Headers

Show Curl Headers

Razvan Ludosanu
Razvan Ludosanu
Founder, learnbackend.dev

The short answer

By default, the [.inline-code]curl[.inline-code] command will only write to the standard output (i.e. stdout) the message body of the response. If you want to also include the HTTP headers and the status code of the response in the output, you can use the [.inline-code]-i[.inline-code] flag (short for include) as follows:

 $ curl -i <url>

Where:

  • [.inline-code]<url>[.inline-code] is the URL of the target server (e.g. [.inline-code]https://example.com[.inline-code], [.inline-code]127.0.0.1:3000[.inline-code]).

Which will output something similar to this:

 HTTP/1.1 200 OK
 X-Powered-By: Express
 Content-Type: text/plain; charset=utf-8
 Content-Length: 2
 ETag: W/"2-nOO9QiTIwXgNtWtBJezz8kv3SLc"
 Date: Fri, 07 Apr 2023 09:14:17 GMT
 Connection: keep-alive
 Keep-Alive: timeout=5

 OK

This flag is often used by developers to get detailed information about how the server processed their request. For example, when performing basic authentication or sending JSON data.

[#easily-recall-syntax]Easily retrieve this command using Warp’s AI Command Search[#easily-recall-syntax]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Entering [.inline-code]curl include response headers with message body[.inline-code] in the AI Command Search will prompt [.inline-code]curl -i[.inline-code], which can then quickly be inserted into your shell by doing [.inline-code]CMD+ENTER[.inline-code].

[#curl-response-headers]Get the [.inline-code]curl[.inline-code] response headers only[#curl-response-headers]

To show the HTTP headers of the response only (i.e. without the message body), you can use the [.inline-code]-I[.inline-code] flag (capital “i”) as follows:

 $ curl -I <url>

Which under the hood, will configure [.inline-code]curl[.inline-code] to send a HEAD request to the server indicating that only the headers of the requested resource should be returned but not its content.

For example:

 $ curl -I 127.0.0.1:3000
 HTTP/1.1 200 OK
 X-Powered-By: Express
 Content-Type: text/plain; charset=utf-8
 Content-Length: 2
 ETag: W/"2-nOO9QiTIwXgNtWtBJezz8kv3SLc"
 Date: Fri, 07 Apr 2023 11:02:10 GMT
 Connection: keep-alive
 Keep-Alive: timeout=5

This flag is particularly useful when you want to retrieve the file size (i.e. the [.inline-code]Content-Length[.inline-code] header) and the last modification date (i.e. the [.inline-code]Last-Modified[.inline-code] header) of a resource located on a FTP server without actually downloading it.

Note that if you try to use this flag in conjunction with another HTTP method such as POST, [.inline-code]curl[.inline-code] might throw the following error:

 $ curl -I -X POST -H 
 ‘Content-Type: application/json’ -d ‘{“token”:”h3ll0”}’ https://example.com
 Warning: You can only select one HTTP request method! You asked for both POST
 Warning: (-d, --data) and HEAD (-I, --head).

[#curl-request-response-headers]Get both the [.inline-code]curl[.inline-code] request and response headers[#curl-request-response-headers]

For debugging purposes, it is sometimes useful to see exactly what is going on under the hood when sending a request with `curl`.

To make [.inline-code]curl[.inline-code] output the HTTP headers of both the request and the response, including the message body of the response and additional information provided by `curl` itself, you can use the `-v` flag (short for verbose) as follows:

 $ curl -v <url>

Where the output is delineated by:

  • [.inline-code]>[.inline-code] representing the data sent.
  • [.inline-code]<[.inline-code] representing the data received.
  • [.inline-code]*[.inline-code] representing additional information.

For example:

 $ curl -v 127.0.0.1:3000
 *   Trying 127.0.0.1:3000...
 * Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
 > GET / HTTP/1.1
 > Host: 127.0.0.1:3000
 > User-Agent: curl/7.85.0
 > Accept: */*
 >
 * Mark bundle as not supporting multiuse
 < HTTP/1.1 200 OK
 < X-Powered-By: Express
 < Content-Type: text/plain; charset=utf-8
 < Content-Length: 2
 < ETag: W/"2-nOO9QiTIwXgNtWtBJezz8kv3SLc"
 < Date: Fri, 07 Apr 2023 11:01:19 GMT
 < Connection: keep-alive
 < Keep-Alive: timeout=5
 <
 * Connection #0 to host 127.0.0.1 left intact

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.