@ricsam/quickjs-fetch 0.2.18 → 0.2.19
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 +16 -5
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/package.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# @ricsam/quickjs-fetch
|
|
2
2
|
|
|
3
|
-
Fetch API and HTTP server handler.
|
|
3
|
+
Fetch API and HTTP server handler for QuickJS runtime.
|
|
4
|
+
|
|
5
|
+
> **Note**: This is a low-level package. For most use cases, use [`@ricsam/quickjs-runtime`](../runtime) with `createRuntime()` instead.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @ricsam/quickjs-fetch
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
4
14
|
|
|
5
15
|
```typescript
|
|
6
16
|
import { setupFetch } from "@ricsam/quickjs-fetch";
|
|
@@ -14,12 +24,13 @@ const handle = setupFetch(context, {
|
|
|
14
24
|
});
|
|
15
25
|
```
|
|
16
26
|
|
|
17
|
-
|
|
27
|
+
## Injected Globals
|
|
28
|
+
|
|
18
29
|
- `fetch`, `Request`, `Response`, `Headers`
|
|
19
30
|
- `FormData`, `AbortController`, `AbortSignal`
|
|
20
31
|
- `serve` (HTTP server handler)
|
|
21
32
|
|
|
22
|
-
|
|
33
|
+
## Usage in QuickJS
|
|
23
34
|
|
|
24
35
|
```javascript
|
|
25
36
|
// Outbound fetch
|
|
@@ -53,7 +64,7 @@ formData.append("name", "John");
|
|
|
53
64
|
formData.append("file", new File(["content"], "file.txt"));
|
|
54
65
|
```
|
|
55
66
|
|
|
56
|
-
|
|
67
|
+
## HTTP Server
|
|
57
68
|
|
|
58
69
|
Register a server handler in QuickJS and dispatch requests from the host:
|
|
59
70
|
|
|
@@ -109,4 +120,4 @@ if (upgrade?.requested) {
|
|
|
109
120
|
// Forward incoming messages
|
|
110
121
|
handle.dispatchWebSocketMessage(connectionId, "Hello from client");
|
|
111
122
|
}
|
|
112
|
-
```
|
|
123
|
+
```
|
package/dist/cjs/package.json
CHANGED
package/dist/mjs/package.json
CHANGED