etherreq 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
# etherreq
|
|
2
2
|
|
|
3
|
+
一个轻量级、无感知的 HTTP 请求库,基于 Fetch封装,支持自动 Token 注入、拦截器、TypeScript 类型定义等功能。
|
|
3
4
|
|
|
5
|
+
## 快速使用
|
|
4
6
|
|
|
5
7
|
安装
|
|
6
8
|
|
|
@@ -10,3 +12,70 @@ npm install etherreq
|
|
|
10
12
|
yarn add etherreq
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
## API 接口
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { etherreq } from 'etherreq';
|
|
19
|
+
|
|
20
|
+
// GET 请求
|
|
21
|
+
import { etherreq } from 'etherreq';
|
|
22
|
+
const ab = async () => {
|
|
23
|
+
const a= await etherreq.get('http://localhost:8081/api/users')
|
|
24
|
+
//获取gat数据
|
|
25
|
+
console.log(a);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// POST 请求
|
|
29
|
+
etherreq.post('/login', { username: 'test', password: '123456' }).then(data => {
|
|
30
|
+
console.log('登录成功:', data);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const b = async () => {
|
|
34
|
+
const user={
|
|
35
|
+
id : 1,
|
|
36
|
+
name : 'name',
|
|
37
|
+
sex : '男',
|
|
38
|
+
age : 18,
|
|
39
|
+
}
|
|
40
|
+
const b1 =await etherreq.post('/add',user);
|
|
41
|
+
console.log(b1);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// 登录方法(自动保存 token)
|
|
45
|
+
etherreq ;
|
|
46
|
+
const login = async () => {
|
|
47
|
+
const user={
|
|
48
|
+
"id": 1,
|
|
49
|
+
"username": "zhy",
|
|
50
|
+
"password": "123456"
|
|
51
|
+
}
|
|
52
|
+
const login =await etherreq.login('users/login',user);
|
|
53
|
+
console.log(login);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### 请求方法
|
|
64
|
+
|
|
65
|
+
etherreq.login(url,data)
|
|
66
|
+
|
|
67
|
+
etherreq.get(url,data)
|
|
68
|
+
|
|
69
|
+
etherreq.delete(url,data)
|
|
70
|
+
|
|
71
|
+
etherreq.head(url,data)
|
|
72
|
+
|
|
73
|
+
etherreq.options(url,data)
|
|
74
|
+
|
|
75
|
+
etherreq.post(url,data)
|
|
76
|
+
|
|
77
|
+
etherreq.put(url,data)
|
|
78
|
+
|
|
79
|
+
etherreq.patch(url,data)
|
|
80
|
+
|
|
81
|
+
在login方法执行后后端需要返回token,之后在执行其他方法时不需要配置token,token会自动携带
|