Application of Axios

Source: Internet
Author: User

First, Introduction

Look at the profile of the official website:

"Promise based HTTP client for the browser and node. js"

HTTP request client based on Promise, which can be used in both the browser and node. js.

Second, features:

1, send xmlhttprequests request in the browser;
2. Send HTTP requests in node. js;
3, support Promise API;
4, interception request and response;
5, conversion request and response data;
6. Automatic conversion of JSON data;
7, the client supports the protection of security from XSRF attacks;

Third, installation (official website)

Iv. Application

1. Send a GET request

Axios.get ('/welfare ', {
Params: {
Giftpackid:1
}
})
. Then (function (res) {
Console.log (RES);
})
. catch (function (res) {
Console.log (RES);
});

2. Send a POST request

Axios.post ('/welfare ', {    giftpackid:1  })  . Then (function (res) {    console.log (res);  })  . catch (function (res) {    console.log (res);  });

  

3. Send multiple concurrent Requests

function Getuseraccount () {  return axios.get ('/welfare ');} function Getuserpermissions () {  return axios.get ('/getwelfare ');} Axios.all ([Getuseraccount (), Getuserpermissions ()])  . Then (Axios.spread (function (acct, perms) {    //OK  }));

4, in addition to the Axios also provides the following several request methods:

Axios.request (config) axios.get (url[, config]) axios.delete (url[, config) axios.head (url[, config]) axios.post (url[, data[, Config]]) axios.put (url[, data[, config]) axios.patch (url[, data[, Config])

  

Application of Axios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.