Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/real-jacket/texios
基于 typescript 实现的 axios
https://github.com/real-jacket/texios
Last synced: about 15 hours ago
JSON representation
基于 typescript 实现的 axios
- Host: GitHub
- URL: https://github.com/real-jacket/texios
- Owner: real-jacket
- License: mit
- Created: 2020-06-20T04:44:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T19:18:25.000Z (about 2 years ago)
- Last Synced: 2024-04-25T09:41:02.956Z (9 months ago)
- Language: TypeScript
- Size: 1.44 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: code-of-conduct.md
Awesome Lists containing this project
README
# Texios [![codecov](https://codecov.io/gh/real-jacket/texios/branch/master/graph/badge.svg)](https://codecov.io/gh/real-jacket/texios)
基于 typescript 实现的 axios
## 基本使用
### 安装
```npm
$ npm install texios// or
$ yarn add texios
```### Example
建议使用 ES 模块
```javascript
import texios from 'texios'texios({
method: 'get',
url: '/simple/get',
params: {
a: 1,
b: 2
}
})
```支持使用 api 的方式
```javascript
texios.request({
method: 'get',
url: '/extend/get'
})texios.get('/more/get')
texios.post('/extend/post', { msg: 'hello post' })
```## 相关 API
### 支持拦截器
```javascript
// 请求拦截
texios.interceptors.request.use(config => {
config.headers.test += '1'
return config
})texios.interceptors.request.use(config => {
config.headers.test += '2'
return config
})
// 响应拦截
texios.interceptors.request.use(config => {
config.headers.test += '3'
return config
})texios.interceptors.response.use(res => {
res.data += '1'
return res
})
```### 支持配置化
```javascript
import texios, { TexiosTransformer } from 'texios'
import qs from 'qs'// 对请求、响应做一个处理
const request = texios.create({
transformRequest: [
function(data) {
return qs.stringify(data)
},
...(texios.defaults.transformRequest as TexiosTransformer[])
],
transformResponse: [
...(texios.defaults.transformResponse as TexiosTransformer[]),
function(data) {
if (typeof data === 'object') {
data.b = 2
}
return data
}
],
headers: {
demo: 'test-xxx'
}
})request({
url: '/config/post',
method: 'post',
data: {
a: 1
}
})
.then(res => {
console.log(res.data)
})
.catch(err => {
console.log(err)
})```