1const https = require('https');
2
3https.get('https://encrypted.google.com/', (res) => {
4 console.log('statusCode:', res.statusCode);
5 console.log('headers:', res.headers);
6
7 res.on('data', (d) => {
8 process.stdout.write(d);
9 });
10
11}).on('error', (e) => {
12 console.error(e);
13});
1HTTP request method is made up of four components:
2Request Method ==> Get, Post, Put, Delete (these are
3the common ones)
4Request URL ==> the URL of the resource
5Request Header ==> Accept-Language, AcceptEncoding, User-Agent, Host
6Request Body ==> This is the data to be sent to the
7resource
8Request Query Parameters : key value pair
9
10HTTP response method is made up of three components:
11Response Status Code ==> 200, 301, 404, 500
12(these are the most common ones)
13Response Header Fields ==> Date, Server, LastModified, Content-Type
14Response Body ==> This is the data that comes
15back to the client from the server.
1JScopieddoneconst https = require('https')const options = { hostname: 'example.com', port: 443, path: '/todos', method: 'GET'}
2const req = https.request(options, res => { console.log(`statusCode: ${res.statusCode}`)
3 res.on('data', d => { process.stdout.write(d) })})
4req.on('error', error => { console.error(error)})
5req.end()
6
1HTTP request method is made up of four components:
2Request Method ==> Get, Post, Put, Delete (these are
3the common ones)
4Request URL ==> the URL of the resource
5Request Header ==> Accept-Language, AcceptEncoding, User-Agent, Host
6Request Body ==> This is the data to be sent to the
7
8HTTP RESPONSE
9resource HTTP -RESPONSE- method is made up of three
10components:
11Response Status Code ==> 200, 301, 404, 500
12(these are the most common ones)
13Response Header Fields ==> Date, Server, LastModified, Content-Type
14Response Body ==> This is the data that comes
15back to the client from the server.