@koishi-ce/plugin-http 1.0.0 → 1.0.1
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 +87 -0
- package/index.d.ts +3 -0
- package/index.mjs +3 -0
- package/package.json +7 -8
- package/readme.md +0 -3
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @koishi-ce/plugin-http
|
|
2
|
+
|
|
3
|
+
**简体中文** | [English](#english)
|
|
4
|
+
|
|
5
|
+
Koishi 的 HTTP 与 WebSocket 客户端基础服务,提供 `ctx.http`。本包是 [@cordisjs/plugin-http](https://github.com/cordiverse/http)(fetch 实现的 axios 风格客户端)在 `@koishi-ce` 名下的再分发存根:内联再导出上游包的全部导出,peer 指向 `@koishi-ce/koishi`,使 CE 生态获得统一的 HTTP 服务而不引入官方包双实例。它是预编译产物包——无 `src/` 目录、不走根 tsdown 构建(根配置显式 exclude),发布内容即 `index.mjs` 与 `index.d.ts`。
|
|
6
|
+
|
|
7
|
+
## 服务
|
|
8
|
+
|
|
9
|
+
`ctx.http` 提供整套请求方法(`get` / `post` / `put` / `patch` / `delete` / `head` 与 `ws` 等)、请求拦截器、`http/file` 文件缓存等事件,请求与响应的形态为 axios 风格(`Response` 携带 `data` / `status` / `headers`)。
|
|
10
|
+
|
|
11
|
+
## 配置项
|
|
12
|
+
|
|
13
|
+
| 字段 | 类型 | 默认值 | 说明 |
|
|
14
|
+
| --- | --- | --- | --- |
|
|
15
|
+
| `baseURL` | string | - | 请求的基础地址(旧名 `endpoint` 已废弃) |
|
|
16
|
+
| `headers` | object | - | 默认请求头 |
|
|
17
|
+
| `timeout` | number | - | 默认超时(毫秒) |
|
|
18
|
+
|
|
19
|
+
单次请求可额外指定 `method` / `params` / `data` / `keepAlive` / `redirect` / `responseType` / `validateStatus` 等。
|
|
20
|
+
|
|
21
|
+
## 用法
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add @koishi-ce/plugin-http
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
plugins:
|
|
29
|
+
http:
|
|
30
|
+
timeout: 10000
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
export async function apply(ctx) {
|
|
35
|
+
const data = await ctx.http.get("https://example.com/api", { params: { q: 1 } });
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
上游文档见 [cordiverse/http](https://github.com/cordiverse/http)。
|
|
40
|
+
|
|
41
|
+
## 许可证
|
|
42
|
+
|
|
43
|
+
[MIT](https://github.com/Koishi-CE/koishi/blob/main/LICENSE)。本包内联再导出 MIT 许可的上游 @cordisjs/plugin-http,版权归属见 [NOTICE](https://github.com/Koishi-CE/koishi/blob/main/NOTICE)。
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## English
|
|
48
|
+
|
|
49
|
+
The HTTP and WebSocket client service for Koishi, providing `ctx.http`. This package is a redistribution stub of [@cordisjs/plugin-http](https://github.com/cordiverse/http) (a fetch-based, axios-style client) under the `@koishi-ce` scope: it re-exports the upstream package in full, with a peer on `@koishi-ce/koishi`, giving the CE ecosystem a unified HTTP service without a duplicate official instance. It is a prebuilt artifact package — no `src/` directory, excluded from the root tsdown build — whose published content is just `index.mjs` and `index.d.ts`.
|
|
50
|
+
|
|
51
|
+
## Service
|
|
52
|
+
|
|
53
|
+
`ctx.http` offers the full request API (`get` / `post` / `put` / `patch` / `delete` / `head`, `ws`, ...), request interceptors, `http/file` caching events and more, in an axios-style shape (`Response` carries `data` / `status` / `headers`).
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
| Field | Type | Default | Description |
|
|
58
|
+
| --- | --- | --- | --- |
|
|
59
|
+
| `baseURL` | string | - | Base URL for requests (the old name `endpoint` is deprecated) |
|
|
60
|
+
| `headers` | object | - | Default request headers |
|
|
61
|
+
| `timeout` | number | - | Default timeout in milliseconds |
|
|
62
|
+
|
|
63
|
+
Per-request options include `method` / `params` / `data` / `keepAlive` / `redirect` / `responseType` / `validateStatus`.
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
bun add @koishi-ce/plugin-http
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
plugins:
|
|
73
|
+
http:
|
|
74
|
+
timeout: 10000
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
export async function apply(ctx) {
|
|
79
|
+
const data = await ctx.http.get("https://example.com/api", { params: { q: 1 } });
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
See [cordiverse/http](https://github.com/cordiverse/http) for upstream documentation.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
[MIT](https://github.com/Koishi-CE/koishi/blob/main/LICENSE). This stub re-exports the MIT-licensed upstream @cordisjs/plugin-http; see [NOTICE](https://github.com/Koishi-CE/koishi/blob/main/NOTICE) for attribution.
|
package/index.d.ts
CHANGED
package/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koishi-ce/plugin-http",
|
|
3
3
|
"description": "HTTP and WebSocket client for Koishi",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -21,18 +21,17 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/
|
|
25
|
-
"directory": "
|
|
24
|
+
"url": "git+https://github.com/Koishi-CE/koishi.git",
|
|
25
|
+
"directory": "plugins/infra/http"
|
|
26
26
|
},
|
|
27
27
|
"bugs": {
|
|
28
|
-
"url": "https://github.com/
|
|
28
|
+
"url": "https://github.com/Koishi-CE/koishi/issues"
|
|
29
29
|
},
|
|
30
|
-
"homepage": "https://github.com/
|
|
30
|
+
"homepage": "https://github.com/Koishi-CE/koishi/tree/main/plugins/infra/http",
|
|
31
31
|
"keywords": [
|
|
32
32
|
"http",
|
|
33
33
|
"fetch",
|
|
34
34
|
"axios",
|
|
35
|
-
"http",
|
|
36
35
|
"undici",
|
|
37
36
|
"client",
|
|
38
37
|
"request",
|
|
@@ -46,10 +45,10 @@
|
|
|
46
45
|
}
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
49
|
-
"koishi": "^
|
|
48
|
+
"@koishi-ce/koishi": "^1.0.0"
|
|
50
49
|
},
|
|
51
50
|
"devDependencies": {
|
|
52
|
-
"@koishi-ce/koishi": "^1.0.
|
|
51
|
+
"@koishi-ce/koishi": "^1.0.8"
|
|
53
52
|
},
|
|
54
53
|
"dependencies": {
|
|
55
54
|
"@cordisjs/plugin-http": "^0.6.3"
|
package/readme.md
DELETED