To construct a request lib.
-
obtain.use
插件模式 -
interceptor
拦截器 -
concurrency
并发数控制 -
cache
接口缓存
...
yarn add obtain-fetch
import obtain from 'obtain-fetch'
// 默认get
obtain('http://localhost:4000/banner', {
method: 'POST',
body: {}
})
obtain.use(http => {
// 请求拦截器
http.interceptor.request.use(
option => option,
err => {},
)
// 响应拦截器
http.interceptor.response.use(
res => res,
err => {},
)
})
默认不控制
obtain.use(http => {
http.concurrency = 10
})