1fetch('',{
2 method:'POST',
3 headers:{
4 'content-type': 'application/json'
5 },
6 body:JSON.stringify(users)
7})
8.then(res=> res.json())
9.then(data => console.log(data))
1const axios = require('axios')
2
3axios
4 .post('https://whatever.com/todos', {
5 todo: 'Buy the milk'
6 })
7 .then(res => {
8 console.log(`statusCode: ${res.statusCode}`)
9 console.log(res)
10 })
11 .catch(error => {
12 console.error(error)
13 })
1const axios = require('axios');
2
3axios.get('https://jsonplaceholder.typicode.com/users')
4 .then(res => {
5 const headerDate = res.headers && res.headers.date ? res.headers.date : 'no response date';
6 console.log('Status Code:', res.status);
7 console.log('Date in Response header:', headerDate);
8
9 const users = res.data;
10
11 for(user of users) {
12 console.log(`Got user with id: ${user.id}, name: ${user.name}`);
13 }
14 })
15 .catch(err => {
16 console.log('Error: ', err.message);
17 });