@allkit/http-client 0.0.2 → 0.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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allkit/http-client",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "description": "this is a http-client package",
5
5
  "type": "module",
6
6
  "main": "./http-client.umd.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allkit/http-client",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "this is a http-client package",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/scripts/build.mjs CHANGED
@@ -7,7 +7,7 @@ import fse from 'fs-extra'
7
7
  import { build } from 'vite'
8
8
  import { viteLibConfig } from '@allkit/vite-config'
9
9
 
10
- const { outputFile } = fse
10
+ const { outputFile, copy } = fse
11
11
 
12
12
  const require = createRequire(import.meta.url)
13
13
 
@@ -81,14 +81,17 @@ const buildAll = async () => {
81
81
  // copy文件
82
82
  // README.md
83
83
  // 样式 index.css
84
- const copyFiles = () => {
84
+ // skills 目录
85
+ const copyFiles = async () => {
85
86
  const markdown = createReadStream(resolve(__dirname, '../README.md'))
86
87
  markdown.pipe(createWriteStream(resolve(__dirname, '../dist/README.md')))
88
+
89
+ await copy(resolve(__dirname, '../skills'), resolve(__dirname, '../dist/skills'))
87
90
  }
88
91
 
89
92
  const buildLib = async () => {
90
93
  await buildAll()
91
- copyFiles()
94
+ await copyFiles()
92
95
  }
93
96
 
94
97
  buildLib()
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: http-client
3
+ description: HTTP 客户端封装,支持小程序,web更多平台,统一处理 API 请求、响应和错误 / HTTP client wrapper for handling API requests
4
+ author: allkit
5
+ category: network
6
+ ---
7
+
8
+ # @allkit/http-client
9
+
10
+ HTTP 客户端,统一处理 API 请求、响应和错误。
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ pnpm add @allkit/http-client
16
+ ```
17
+
18
+ ## Methods
19
+
20
+ | Method | Description |
21
+ |--------|-------------|
22
+ | [Http.get](./references/get.md) | GET 请求 |
23
+ | [Http.post](./references/post.md) | POST 请求 |
24
+ | [Http.put](./references/put.md) | PUT 请求 |
25
+ | [Http.delete](./references/delete.md) | DELETE 请求 |
26
+ | [Http.patch](./references/patch.md) | PATCH 请求 |
27
+
28
+ ## Usage
29
+
30
+ ```ts
31
+ import Http from '@allkit/http-client'
32
+
33
+ const res = await Http.post({
34
+ url: '/api/user/list',
35
+ data: { page: 1, pageSize: 10 }
36
+ })
37
+ ```
@@ -0,0 +1,50 @@
1
+ import Http from '@allkit/http-client'
2
+
3
+ type UserInfo = {
4
+ id: number
5
+ name: string
6
+ email: string
7
+ }
8
+
9
+ type UserListParams = {
10
+ page: number
11
+ pageSize: number
12
+ keyword?: string
13
+ }
14
+
15
+ export const apiGetUserList = (params: UserListParams) => {
16
+ return Http.get<{ list: UserInfo[]; total: number }>({
17
+ url: '/user/list',
18
+ params,
19
+ })
20
+ }
21
+
22
+ export const apiCreateUser = (data: Omit<UserInfo, 'id'>) => {
23
+ return Http.post<UserInfo>({
24
+ url: '/user',
25
+ data,
26
+ })
27
+ }
28
+
29
+ export const apiUpdateUser = (id: number, data: Partial<UserInfo>) => {
30
+ return Http.put<UserInfo>({
31
+ url: `/user/${id}`,
32
+ data,
33
+ })
34
+ }
35
+
36
+ export const apiDeleteUser = (id: number) => {
37
+ return Http.delete({
38
+ url: `/user/${id}`,
39
+ })
40
+ }
41
+
42
+ export const apiUploadFile = (file: File) => {
43
+ const formData = new FormData()
44
+ formData.append('file', file)
45
+ return Http.post<{ url: string }>({
46
+ url: '/upload',
47
+ data: formData,
48
+ headers: { 'content-Type': 'multipart/form-data' },
49
+ })
50
+ }
@@ -0,0 +1,17 @@
1
+ # Http.delete
2
+
3
+ 发送 DELETE 请求
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function delete<T = any>(config: RequestConfig): Promise<T>
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ await Http.delete({
15
+ url: '/api/user/1'
16
+ })
17
+ ```
@@ -0,0 +1,28 @@
1
+ # Http.get
2
+
3
+ 发送 GET 请求
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function get<T = any>(config: RequestConfig): Promise<T>
9
+ ```
10
+
11
+ ## Config
12
+
13
+ | Property | Type | Required | Description |
14
+ |-----------|------|----------|-------------|
15
+ | `url` | `string` | Yes | 请求地址 |
16
+ | `params` | `object` | No | URL 参数 |
17
+ | `headers` | `object` | No | 请求头 |
18
+ | `timeout` | `number` | No | 超时时间 |
19
+ | `responseType` | `string` | No | 响应类型 |
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ const res = await Http.get<{ list: User[]; total: number }>({
25
+ url: '/api/user/list',
26
+ params: { page: 1, pageSize: 10 }
27
+ })
28
+ ```
@@ -0,0 +1,18 @@
1
+ # Http.patch
2
+
3
+ 发送 PATCH 请求
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function patch<T = any>(config: RequestConfig): Promise<T>
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ const res = await Http.patch<User>({
15
+ url: '/api/user/1',
16
+ data: { name: '王五' }
17
+ })
18
+ ```
@@ -0,0 +1,27 @@
1
+ # Http.post
2
+
3
+ 发送 POST 请求
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function post<T = any>(config: RequestConfig): Promise<T>
9
+ ```
10
+
11
+ ## Config
12
+
13
+ | Property | Type | Required | Description |
14
+ |-----------|------|----------|-------------|
15
+ | `url` | `string` | Yes | 请求地址 |
16
+ | `data` | `object` | No | 请求体数据 |
17
+ | `headers` | `object` | No | 请求头 |
18
+ | `timeout` | `number` | No | 超时时间 |
19
+
20
+ ## Example
21
+
22
+ ```ts
23
+ const res = await Http.post<User>({
24
+ url: '/api/user',
25
+ data: { name: '张三', email: 'test@example.com' }
26
+ })
27
+ ```
@@ -0,0 +1,18 @@
1
+ # Http.put
2
+
3
+ 发送 PUT 请求
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function put<T = any>(config: RequestConfig): Promise<T>
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ const res = await Http.put<User>({
15
+ url: '/api/user/1',
16
+ data: { name: '李四' }
17
+ })
18
+ ```
File without changes