Node.js http.ClientRequest.end() API Last Updated : 08 Jul, 2021 Comments Improve Suggest changes Like Article Like Report The http.ClientRequest.end() is an inbuilt application programming interface of class ClientRequest within http module which is used to finish sending the request. If any parts of the body are unsent. Syntax: const request.end([data[, encoding]][, callback]) Parameters: This method takes the data as an input. Return Value : This method returns nothing but a callback function. Example 1: JavaScript // Node.js program to demonstrate the // request.end() APi // Importing http module const http = require('http'); // Create an HTTP server http.createServer((req, res) => {}).listen(3000, '127.0.0.1', () => { // getting client request const req = http.request({ port: 3000, host: '127.0.0.1', }); req.setHeader('content-type', 'text/html'); // finishing sending the request req.end() // getting header // by using getHeader() api console.log("header :- " + req.getHeader('content-type')) process.exit(0) }); Output: Example 2: JavaScript // Node.js program to demonstrate the // request.end() APi // Importing http module const http = require('http'); // Create an HTTP server const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('okay'); }); // Now that server is running server.listen(3000, '127.0.0.1', () => { // make a request const options = { port: 3000, host: '127.0.0.1', headers: { 'Connection': 'Upgrade', 'Upgrade': 'websocket' } }; // getting client request const req = http.request(options); req.setHeader('Cookie', ['type=ninja', 'language=javascript']); // getting header // by using getHeader() api const v = req.getHeader('Cookie'); // finishing sending the request req.end() // display the result console.log("header :- " + v) process.exit(0) }); Output: Reference: https://nodejs.org/dist/latest-v12.x/docs/api/http.html#http_request_end_data_encoding_callback Comment More infoAdvertise with us Next Article Node.js http.ClientRequest.end() API rohitprasad3 Follow Improve Article Tags : Web Technologies Node.js NodeJS-API Similar Reads Node.js http.ClientRequest.host API The http.ClientRequest.host is an inbuilt API : Application Programming Interface of class ClientRequest within http module which is used to get the object of client request host. Syntax: const request.host Parameters: This API does not accept any argument as parameter. Return Value : This method re 1 min read Node.js http.ClientRequest.getHeader() API The http.ClientRequest.getHeader() is  an inbuilt application programming interface of class ClientRequest within http module which is used to get the header object of the particular header name. Syntax: const request.getHeader(name) Parameters: This method takes the name of the header as a paramete 2 min read Node.js http.ClientRequest.method API The http.ClientRequest.method is an inbuilt application programming interface of class ClientRequest within http module which is used to get the object of client request method. Syntax: const request.method Parameters: This API does not accept any argument as parameter. Return Value : This method re 1 min read Node.js http.ClientRequest.writableEnded API The http.ClientRequest.writableEnded is an inbuilt application programming interface of class ClientRequest within http module which is used to check if the request.end() has been called or not. Syntax: const request.writableEnded Parameters: This API does not accept any argument as parameter. Retur 1 min read Node.js http.ClientRequest.abort() Method The http.ClientRequest.abort() is an inbuilt application programming interface of class Client Request within http module which is used to abort the client request. Syntax: ClientRequest.abort() Parameters: This method does not accept any argument as a parameter. Return Value: This method does not r 2 min read Like