Skip to content

Commit 20e9e63

Browse files
authored
Merge pull request #15 from rescript-lang/refactor-fetch
Improve fetch binding
2 parents 47c6b2c + fb6427a commit 20e9e63

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

src/DOMAPI/Window.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/DOMAPI/Window.res

+19-2
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,33 @@ external structuredClone: (window, 't, ~options: structuredSerializeOptions=?) =
294294
"structuredClone"
295295

296296
/**
297+
`fetch(window, string, init)`
298+
299+
Starts the process of fetching a resource from the network,
300+
returning a promise that is fulfilled once the response is available.
301+
302+
```res
303+
let response = await window->Window.fetch("https://rescript-lang.org")
304+
```
305+
297306
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
298307
*/
299308
@send
300-
external fetch: (window, ~input: request, ~init: requestInit=?) => Promise.t<response> = "fetch"
309+
external fetch: (window, string, ~init: requestInit=?) => Promise.t<response> = "fetch"
301310

302311
/**
312+
`fetch_withRequest(window, request, init)`
313+
314+
Starts the process of fetching a resource from the network,
315+
returning a promise that is fulfilled once the response is available.
316+
317+
```res
318+
let response = await window->Window.fetch(myRequest)
319+
```
303320
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
304321
*/
305322
@send
306-
external fetch2: (window, ~input: string, ~init: requestInit=?) => Promise.t<response> = "fetch"
323+
external fetch_withRequest: (window, request, ~init: requestInit=?) => Promise.t<response> = "fetch"
307324

308325
/**
309326
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)

src/Global.res

+21-2
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,33 @@ external createImageBitmap18: (
480480
external structuredClone: ('t, ~options: structuredSerializeOptions=?) => 't = "structuredClone"
481481

482482
/**
483+
`fetch(string, init)`
484+
485+
Starts the process of fetching a resource from the network,
486+
returning a promise that is fulfilled once the response is available.
487+
488+
```res
489+
let response = await fetch("https://rescript-lang.org")
490+
```
491+
483492
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
484493
*/
485-
external fetch: (~input: request, ~init: requestInit=?) => Promise.t<response> = "fetch"
494+
external fetch: (string, ~init: requestInit=?) => Promise.t<response> = "fetch"
486495

487496
/**
497+
`fetch_withRequest(request, init)`
498+
499+
Starts the process of fetching a resource from the network,
500+
returning a promise that is fulfilled once the response is available.
501+
502+
```res
503+
let response = await fetch(myRequest)
504+
```
505+
488506
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
489507
*/
490-
external fetch2: (~input: string, ~init: requestInit=?) => Promise.t<response> = "fetch"
508+
@send
509+
external fetch_withRequest: (request, ~init: requestInit=?) => Promise.t<response> = "fetch"
491510

492511
/**
493512
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)

tests/Global__test.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Global__test.res

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
open WebAPI.Global
2+
3+
let response = await fetch("https://rescript-lang.org/")

0 commit comments

Comments
 (0)