Hello
This commit is contained in:
13
http/axios.js
Normal file
13
http/axios.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const axios = require("axios");
|
||||
|
||||
axios
|
||||
.post("https://whatever.com/todos", {
|
||||
todo: "Buy the milk",
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(`statusCode: ${res.status}`);
|
||||
console.log(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
21
http/request-get.js
Normal file
21
http/request-get.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const https = require("https");
|
||||
const options = {
|
||||
hostname: "www.naver.com",
|
||||
port: 443,
|
||||
path: "/",
|
||||
method: "GET",
|
||||
};
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
console.log(`statusCode: ${res.statusCode}`);
|
||||
|
||||
res.on("data", (d) => {
|
||||
process.stdout.write(d);
|
||||
});
|
||||
});
|
||||
|
||||
req.on("error", (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
req.end();
|
||||
32
http/request-post.js
Normal file
32
http/request-post.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const https = require("https");
|
||||
const data = new TextEncoder().encode(
|
||||
JSON.stringify({
|
||||
todo: "Buy the milk 🍼",
|
||||
})
|
||||
);
|
||||
|
||||
const options = {
|
||||
hostname: "example.com",
|
||||
port: 443,
|
||||
path: "/todos",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": data.length,
|
||||
},
|
||||
};
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
console.log(`statusCode: ${res.statusCode}`);
|
||||
|
||||
res.on("data", (d) => {
|
||||
process.stdout.write(d);
|
||||
});
|
||||
});
|
||||
|
||||
req.on("error", (error) => {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
req.write(data);
|
||||
req.end();
|
||||
13
http/server.js
Normal file
13
http/server.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const http = require("http");
|
||||
|
||||
const port = 18080;
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.setHeader("Content-Type", "text/html");
|
||||
res.end("<h1>Hello, World!</h1>");
|
||||
});
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`Server running at port ${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user