HTTP requests
How to add headers to a cURL request
Use the -H flag to add HTTP headers to a curl request, including Authorization, Content-Type, Accept, and custom API headers.
Basic header syntax
Each header is passed with -H followed by a quoted header name and value. You can use -H multiple times in the same command.
curl https://api.example.com/items \
-H "Accept: application/json" \
-H "X-Api-Key: YOUR_API_KEY"Common headers
Accept tells the server what response format you prefer. Content-Type tells the server what format your request body uses. Authorization carries credentials such as bearer tokens or basic auth values.
Custom headers like X-Api-Key are common in vendor APIs.
Headers and security
Headers often contain secrets. API keys, session cookies, bearer tokens, and signed request values should not be committed to git or pasted into public issues.
When sharing curl examples, replace secret values with placeholders like YOUR_API_KEY.
Headers in generated code
When you convert curl to code, headers usually become a dictionary, object, map, or array depending on the language. The header names and values should stay the same.
Try it with curlcode
Have a curl command already? Paste it into one of the converters below to generate language-specific HTTP request code.
Frequently asked questions
Can I add multiple headers in curl?
Yes. Use one -H flag per header.
Are header names case-sensitive?
HTTP header names are generally case-insensitive, but it is best to preserve the spelling used by the API documentation.
Where do bearer tokens go?
Bearer tokens usually go in the Authorization header as Authorization: Bearer YOUR_TOKEN.
Do headers convert cleanly to code?
Yes. Headers are one of the easiest parts of a curl command to convert into application code.
Related guides
What does cURL mean?
Learn what cURL means, why developers use it, and how a simple curl command turns a URL into a repeatable API request.
What is a cURL command?
A practical explanation of curl commands, their structure, common flags, and how developers use them to test APIs.
How to copy as cURL from Chrome DevTools
Use Chrome DevTools to copy a real browser request as cURL, inspect headers and cookies, and convert it into reusable code.