Passing Custom Headers to Curl [Node.js Code]

To make a request with a custom HTTP header using Curl, you must pass that header with the -H command line option in "header: value" format. In this Curl Custom Headers example, we send a custom HTTP header to the ReqBin echo URL. The target URL is passed as the first command-line parameter, and the custom header is passed as the second command-line parameter to the Curl command. You can pass multiple custom HTTP headers to Curl by repeating the -H "header: value" command line option. Click Run to execute the Curl Custom Headers example online and see the results. The Node.js code was automatically generated for the Curl Custom Headers example.
Passing Custom Headers to Curl [Node.js Code] Run
curl https://reqbin.com/echo/get/json
    -H "X-Powered-By: ReqBin HTTP Client"
Updated: Viewed: 20800 times
Node.js code for Curl Custom Headers example

Node.js code for Curl Custom Headers Example

This Node.js code snippet was generated automatically for the Curl Custom Headers example.
<< Back to the Curl Custom Headers example

What is Curl?

Curl is a popular open-source command-line tool and cross-platform library (libcurl) for transferring data between servers, designed to work without user intervention. Curl can upload or download data using popular protocols including HTTP, HTTPS, SFTP, SCP, and FTP. Curl has built-in support for HTTP Cookies, SSL, proxies, certificate validation, user authentication and works on all modern platforms and hardware, including Linux, Windows, and macOS.

What is HTTP?

HTTP (Hypertext Transfer Protocol) is a protocol for exchanging data between multiple network devices that are used to transfer data between an HTTP client (browser or mobile application) and a server. Now the HTTP protocol is the most popular and primary communication method on the Internet. HTTP is built on messages called "request" and "response" based on the client-server architecture. Devices communicate with each other by sending HTTP requests and receiving HTTP responses.

What is Custom Headers?

HTTP headers allow clients to send information to the server and return data to the client. The headers are usually invisible to the end-user and are only visible to server soft and network administrators. Custom headers are intended to provide additional information related to the current request or response, or for troubleshooting purposes.

How to pass Custom HTTP Headers to Curl?

You can use the -H "header: value" command line option to pass custom headers to Curl. Below is an example of sending a custom HTTP header with Curl:

Curl Custom Headers Example
curl https://reqbin.com/echo/get/json
   -H "X-Powered-By: ReqBin HTTP Client"

See also

Generate code snippets for Node.js and other programming languages

Convert your Curl Custom Headers request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the Node.js code generator.