How is an HTTP POST request made in node.js?

后端 未结 21 2402
南方客
南方客 2020-11-21 23:54

How can I make an outbound HTTP POST request, with data, in node.js?

21条回答
  •  渐次进展
    2020-11-22 00:27

    If you are looking for promise based HTTP requests, axios does its job nicely.

      const axios = require('axios');
    
      axios.post('/user', {firstName: 'Fred',lastName: 'Flintstone'})
          .then((response) => console.log(response))
          .catch((error) => console.log(error));
    

    OR

    await axios.post('/user', {firstName: 'Fred',lastName: 'Flintstone'})
    

提交回复
热议问题