const superagent = require("superagent");
(async () => {
try {
const res = await superagent.get(
"https://jsonplaceholder.typicode.com/users"
);
const headerDate =
res.headers && res.headers.date ? res.headers.date : "no response date";
console.log("Status Code:", res.statusCode);
console.log("Date in Response header:", headerDate);
const users = res.body;
for (user of users) {
console.log(`Got user with id: ${user.id}, name: ${user.name}`);
}
console.log("------------------------------------");
} catch (err) {
console.log(err.message); //can be console.error
console.log("------------------------------------");
}
})();
(async () => {
try {
const res = await superagent.post(url).send({ version: "2.0.1" });
console.log(res.body);
console.log(res.body.code);
console.log(res.body.data);
console.log(res.body.message);
console.log("------------------------------------");
} catch (err) {
console.log(err.message); //can be console.error
console.log("------------------------------------");
}
})();