https://github.com/saber2pr/request
:stars: A HTTP Request library.
https://github.com/saber2pr/request
ajax http xhr
Last synced: 1 day ago
JSON representation
:stars: A HTTP Request library.
- Host: GitHub
- URL: https://github.com/saber2pr/request
- Owner: Saber2pr
- Created: 2019-05-03T04:06:35.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-05T08:59:38.000Z (about 5 years ago)
- Last Synced: 2025-07-06T06:07:56.294Z (6 days ago)
- Topics: ajax, http, xhr
- Language: TypeScript
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @saber2pr/request
[](https://www.npmjs.com/package/@saber2pr/request)
> 提供全局拦截器配置
# 为什么?
已经有 axios...
qwq
axios 在使用 rollup 打包时会发生错误,无法处理 http 依赖(别和我说 webpack :(
```bash
npm install @saber2pr/request
```# API
```ts
new Request(baseConfig)
```## 常用请求
1. new Request().get(url, config)
2. new Request().post(url, config)
3. new Request().put(url, config)
4. new Request().delete(url, config)
## 自定义请求
new Request().fetch
## 拦截器
1. new Request().interceptors
2. new Request().interceptors.request
3. new Request().interceptors.request.use
4. new Request().interceptors.requestInterceptors
5. new Request().interceptors.response
6. new Request().interceptors.response.use
7. new Request().interceptors.responseInterceptors```ts
import axios from "@saber2pr/request" // const axios = new Request()axios.interceptors.request.use(config => {
/** code **/config.headers.Authorization =
"Basic " + Base64.encode(`${username}:${password}`)return config
})axios.interceptors.response.use(res => {
switch (res.status) {
case 200:
return rescase 401:
push("/login")
breakdefault:
push("/error")
}
})
```### 还需要说么。。
使用 typescript 编码,不需要文档!qwq
```ts
npm startnpm run dev
npm run serve
```# Author
> saber2pr