Back to blog

    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.

    5 min readUpdated 2026-04-28

    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.

    Add headers with curl
    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