Giter VIP home page Giter VIP logo

mini-axios's Introduction

Axios 简介

是什么?

Axios 是一个基于promise 网络请求库,作用于 node.js 和浏览器中。是同构的。(基于 promise 的 http 客户端)

特性

  • 同构:从浏览器创建 XMLHttpRequests,从 node.js 创建 http 请求
  • 支持 promiseAPI
  • 拦截器:拦截请求和响应
  • 转换请求和相应数据
  • 取消请求
  • 自动转换 JSON 数据
  • 客户端支持防御 XSRF

用法

原理

  • 创建 axios,包含 defaults 和 interceptors 属性;
  • 设置拦截器,向拦截器 handlers 属性中添加对象
  • 调用 axios,触发 Axios.prototype.request 调用 把请求拦截器 handlers 属性加到 chains 数组前边 把响应拦截器 handlers 属性加到 chains 数组后边 遍历 chains 数组,处理请求拦截,触发 dispatchRequest 函数
  • 触发 xhrAdapte 函数,发送请求,状态改为 padding 请求完成,触发 resolve,继续遍历 chains 数组,处理响应拦截
  • 触发 axios().then()或 axios().catch()函数

json-server

json-server

补充

  • 同构应用程序是代码可以在服务器和客户端中运行的应用程序。

mini-axios's People

Contributors

betty985 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.