A header is a name and a value sent along with a web request, such as an API key. curl -H adds one to the request curl sends.
Every command and output on this page is real, run in Terminal with the curl that comes with macOS 26 (curl 8.7.1).
Syntax
Syntax
curl -H "Name: value" URL
-H: add a header. Repeat it for each header you need."Name: value": the header’s name, a colon and its value, in quotes.URL: the address to send the request to.
See -H, --header in the curl manual.
The Example
A request to example.com, a domain kept for examples, with the header X-Greeting: hello. -v makes curl print the request it sends.
Step 1: Send the Request
Terminal
curl -v -H "X-Greeting: hello" https://example.com/
Output (the lines that matter)
> GET / HTTP/2
> Host: example.com
> User-Agent: curl/8.7.1
> Accept: */*
> X-Greeting: hello
Lines that start with > are the request curl sent: its own headers, then yours on the last line. The page’s HTML follows after them.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out the colon: -H "X-Greeting hello" | curl doesn’t send the header at all: no X-Greeting line among the > lines | Write a colon after the name: X-Greeting: hello |
FAQ
How do I send an API key with curl?
Many APIs read the key from a header, so send it with -H, such as -H "X-N8N-API-KEY: your-key" for n8n’s API.
Conclusion
Add -H "Name: value" for each header, and use -v to see what curl really sent.
Additional Resources
- -H, --header (curl manual)
- -v, --verbose (curl manual)
macOS is a trademark of Apple Inc.
