@@ -35,7 +35,7 @@ Automatic Parsed type:
35
35
36
36
#### Installation
37
37
38
- ``` shell
38
+ ``` powershell
39
39
npm install koajax
40
40
```
41
41
@@ -55,15 +55,16 @@ npm install koajax
55
55
56
56
#### Installation
57
57
58
- ``` shell
59
- npm install koajax jsdom
58
+ ``` powershell
59
+ npm install koajax core-js jsdom
60
60
```
61
61
62
62
#### ` index.ts `
63
63
64
64
``` javascript
65
+ import { polyfill } from ' koajax/source/polyfill' ;
66
+
65
67
import { HTTPClient } from ' koajax' ;
66
- import { polyfill } from ' koajax/source/polyfill'
67
68
68
69
const origin = ' https://your-target-origin.com' ;
69
70
@@ -80,7 +81,7 @@ polyfill(origin).then(() => {
80
81
81
82
#### Execution
82
83
83
- ``` shell
84
+ ``` powershell
84
85
npx tsx index.ts
85
86
```
86
87
@@ -141,9 +142,44 @@ document.querySelector('input[type="file"]').onchange = async ({
141
142
};
142
143
```
143
144
145
+ #### Single HTTP request based on Fetch ` duplex ` streams
146
+
147
+ > This experimental feature has [ some limitations] [ 7 ] .
148
+
149
+ ``` diff
150
+ - import { request } from 'koajax';
151
+ + import { requestFetch } from 'koajax';
152
+
153
+ document.querySelector('input[type="file"]').onchange = async ({
154
+ target: { files }
155
+ }) => {
156
+ for (const file of files) {
157
+ - const { upload, download, response } = request({
158
+ + const { upload, download, response } = requestFetch({
159
+ method: 'POST',
160
+ path: '/files',
161
+ + headers: {
162
+ + 'Content-Type': file.type,
163
+ + 'Content-Length': file.size + ''
164
+ + },
165
+ - body: file,
166
+ + body: file.stream(),
167
+ responseType: 'json'
168
+ });
169
+
170
+ for await (const { loaded } of upload)
171
+ console.log(`Upload ${file.name} : ${(loaded / file.size) * 100}%`);
172
+
173
+ const { body } = await response;
174
+
175
+ console.log(`Upload ${file.name} : ${body.url}`);
176
+ }
177
+ };
178
+ ```
179
+
144
180
#### Multiple HTTP requests based on ` Range ` header
145
181
146
- ``` shell
182
+ ``` powershell
147
183
npm i native-file-system-adapter # Web standard API polyfill
148
184
```
149
185
@@ -176,7 +212,7 @@ document.querySelector('#download').onclick = async () => {
176
212
177
213
### Global Error fallback
178
214
179
- ``` shell
215
+ ``` powershell
180
216
npm install browser-unhandled-rejection # Web standard API polyfill
181
217
```
182
218
@@ -226,3 +262,4 @@ document.querySelector('input[type="file"]').onchange = async ({
226
262
[ 4 ] : https://www.jsdelivr.com/package/npm/koajax
227
263
[ 5 ] : https://nodei.co/npm/koajax/
228
264
[ 6 ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of#Iterating_over_async_generators
265
+ [ 7 ] : https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions
0 commit comments