Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/07akioni/irw
https://github.com/07akioni/irw
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/07akioni/irw
- Owner: 07akioni
- Created: 2021-11-15T13:59:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-11-24T10:22:45.000Z (about 3 years ago)
- Last Synced: 2024-11-24T16:26:00.114Z (about 1 month ago)
- Language: TypeScript
- Size: 29.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# irw
`irw` means `isomorphic request wrapper`.
You can use it to wrap different http request clients into a isomorphic request client.
`irw` 意思是 `同构请求包装器`。
你可以使用它去包装不同的 http 库,获取统一的请求接口。
## Features
- request(config)
- request.get(url, config)
- request.post(url, config)
- request.put(url, config)
- interceptors## Todo
- progress
- cancel## Examples
```ts
import { irw } from "irw";// for axios
// 使用 axios
const request = irw({
request: axios
});// for weixin miniapp
// 使用微信小程序
const request = irw({
request: wx.request
});// interceptor
// 拦截器
request.interceptors.request.use((config) => {
return {
...config,
headers: {
...config.headers,
token: "foo",
},
};
});request.interceptors.request.use(async (config) => {
return {
...config,
headers: {
...config.headers,
token: await getToken(),
},
};
});// request
// Currently only get, post and post is supports
request.get('/url', { params: {} }).then()
request.post('/url', { data: {}, params: {} }).then()
request.put('/url', { data: {}, params: {} }).then()
request({
url: '/url'
method: 'post',
data: {}
}).then()
```