@@ -35,7 +35,7 @@ Automatic Parsed type:
3535
3636#### Installation
3737
38- ``` shell
38+ ``` powershell
3939npm install koajax
4040```
4141
@@ -55,15 +55,16 @@ npm install koajax
5555
5656#### Installation
5757
58- ``` shell
59- npm install koajax jsdom
58+ ``` powershell
59+ npm install koajax core-js jsdom
6060```
6161
6262#### ` index.ts `
6363
6464``` javascript
65+ import { polyfill } from ' koajax/source/polyfill' ;
66+
6567import { HTTPClient } from ' koajax' ;
66- import { polyfill } from ' koajax/source/polyfill'
6768
6869const origin = ' https://your-target-origin.com' ;
6970
@@ -80,7 +81,7 @@ polyfill(origin).then(() => {
8081
8182#### Execution
8283
83- ``` shell
84+ ``` powershell
8485npx tsx index.ts
8586```
8687
@@ -141,9 +142,44 @@ document.querySelector('input[type="file"]').onchange = async ({
141142};
142143```
143144
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+
144180#### Multiple HTTP requests based on ` Range ` header
145181
146- ``` shell
182+ ``` powershell
147183npm i native-file-system-adapter # Web standard API polyfill
148184```
149185
@@ -176,7 +212,7 @@ document.querySelector('#download').onclick = async () => {
176212
177213### Global Error fallback
178214
179- ``` shell
215+ ``` powershell
180216npm install browser-unhandled-rejection # Web standard API polyfill
181217```
182218
@@ -226,3 +262,4 @@ document.querySelector('input[type="file"]').onchange = async ({
226262[ 4 ] : https://www.jsdelivr.com/package/npm/koajax
227263[ 5 ] : https://nodei.co/npm/koajax/
228264[ 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