Skip to content

Commit 08e0ae3

Browse files
committed
Sample code for HTTP client APIs
1 parent d579c47 commit 08e0ae3

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const http = require('http');
2+
3+
const request = http.get('http://httpbin.org/get', (response) => {
4+
response.on('data', (data) => {
5+
console.log(data.toString());
6+
});
7+
});
8+
9+
request.end();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const http = require('http');
2+
3+
const url = 'http://httpbin.org/get';
4+
const options = {
5+
auth: 'myuser:mypass',
6+
headers: {
7+
Test: 'Some Value'
8+
}
9+
};
10+
11+
const request = http.get(url, options, (response) => {
12+
response.on('data', (data) => {
13+
console.log(data.toString());
14+
});
15+
});
16+
17+
request.end();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const http = require('http');
2+
3+
const url = 'http://httpbin.org/post';
4+
const options = {
5+
method: 'POST',
6+
};
7+
8+
const request = http.request(url, options, (response) => {
9+
response.on('data', (data) => {
10+
console.log(data.toString());
11+
});
12+
});
13+
14+
request.write('Hello world.');
15+
request.end();

0 commit comments

Comments
 (0)