HTTP client calls
Send HTTP requests and process their responses asynchronously.
Node.js · Class
http.ClientRequest is the writable stream representing an in-progress HTTP client request. It is returned by http.request(), accepts request data and headers, and emits the server response when response headers arrive.
ClientRequest is the writable stream returned by http.request() while an HTTP request is in progress. Configure its headers or write request data, listen for the response and errors, then call end() to complete a request that has no more body data.
class http.ClientRequestAn instance of the http.ClientRequest class is returned by http.request().
const http = require('node:http');
const request = http.request('http://example.com', (response) => {
response.on('data', (chunk) => process.stdout.write(chunk));
response.on('end', () => console.log('\nDone'));
});
request.on('error', console.error);
request.end();This creates a ClientRequest through http.request(), consumes the response, handles request errors, and ends the request.
Send HTTP requests and process their responses asynchronously.
Upload form data, JSON, or file contents in a request body.
Set, inspect, or remove request headers before transmission.
http.request()http.IncomingMessagesetHeader(name, value)getHeader(name)removeHeader(name)request.end()