Git Product home page Git Product logo

readit-ts-axios's Introduction

ts-axios

参数解析
  • 参数为数组
  • 参数为对象
  • 参数为日期
  • 特殊字符
  • 空值忽略
  • 丢弃url中的hash标记
  • 保留url中已有的参数
处理步骤
  • 基础功能实现
  1. 完成XMLHttpRequest对象接入
  2. 处理请求url参数
  3. 处理请求体body参数
  4. 处理请求header参数
  5. 获取响应数据
  6. json化response中的data和header
  • 异常情况处理
  1. 处理网络异常错误
  2. 处理超时错误
  3. 处理非2xx状态码
  • 接口扩展
  1. 扩展接口
  2. 函数重载实现多个参数
  3. 数据响应支持泛型
  • 拦截器实现
  1. 通过拦截器管理类和promise实现链式调用
  • 默认配置实现
  1. 合并请求配置
  2. 请求和响应配置化
  • 取消请求
  • 请求跨域
  • XSRF防御
  • 上传 和 下载
  • HTTP授权
  • 自动化合法状态码
  • 自动化参数序列化
  • baseURL
  • 静态方法扩展(鸡肋)

CSRF 的防御手段有很多,比如验证请求的 referer,但是 referer 也是可以伪造的,所以杜绝此类攻击的一种方式是服务器端要求每次请求都包含一个 token,这个 token 不在前端生成,而是在我们每次访问站点的时候生成,并通过 set-cookie 的方式种到客户端,然后客户端发送请求的时候,从 cookie 中对应的字段读取出 token,然后添加到请求 headers 中。这样服务端就可以从请求 headers 中读取这个 token 并验证,由于这个 token 是很难伪造的,所以就能区分这个请求是否是用户正常发起的。

readit-ts-axios's People

Watchers

Alvin Xin 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.