基于 Promise 的 HTTP 客户端 Axios

码农软件 · 软件分类 · 服务器端JavaScript · 2019-04-13 14:28:42

软件介绍

Axios,基于 Promise 的 HTTP 客户端,可以工作于浏览器中,也可以在 node.js 中使用。

功能:

  • 从浏览器中创建 XMLHttpRequest

  • 从 node.js 中创建 http 请求

  • 支持 Promise API

  • 拦截请求和响应

  • 转换请求和响应数据

  • 取消请求

  • 自动转换 JSON 数据

  • 客户端支持防止 XSRF 攻击

示例代码:

执行一个 GET 请求

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
// Optionally the request above could also be done as
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

执行一个 POST 请求

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

执行多个并发请求

function getUserAccount() {
  return axios.get('/user/12345');
}
function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
  .then(axios.spread(function (acct, perms) {
    // Both requests are now complete
  }));

本文地址:https://codercto.com/soft/d/3494.html

Python语言及其应用

Python语言及其应用

[美] Bill Lubanovic / 丁嘉瑞、梁杰、禹常隆 / 人民邮电出版社 / 2016-1 / 79.00元

本书介绍Python 语言的基础知识及其在各个领域的具体应用,基于最新版本3.x。书中首先介绍了Python 语言的一些必备基本知识,然后介绍了在商业、科研以及艺术领域使用Python 开发各种应用的实例。文字简洁明了,案例丰富实用,是一本难得的Python 入门手册。一起来看看 《Python语言及其应用》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

MD5 加密
MD5 加密

MD5 加密工具