Skip to content

Improve fetch binding #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/DOMAPI/Window.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/DOMAPI/Window.res
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,33 @@ external structuredClone: (window, 't, ~options: structuredSerializeOptions=?) =
"structuredClone"

/**
`fetch(window, string, init)`

Starts the process of fetching a resource from the network,
returning a promise that is fulfilled once the response is available.

```res
let response = await window->Window.fetch("https://rescript-lang.org")
```

[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
*/
@send
external fetch: (window, ~input: request, ~init: requestInit=?) => Promise.t<response> = "fetch"
external fetch: (window, string, ~init: requestInit=?) => Promise.t<response> = "fetch"

/**
`fetch_withRequest(window, request, init)`

Starts the process of fetching a resource from the network,
returning a promise that is fulfilled once the response is available.

```res
let response = await window->Window.fetch(myRequest)
```
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
*/
@send
external fetch2: (window, ~input: string, ~init: requestInit=?) => Promise.t<response> = "fetch"
external fetch_withRequest: (window, request, ~init: requestInit=?) => Promise.t<response> = "fetch"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)
Expand Down
23 changes: 21 additions & 2 deletions src/Global.res
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,33 @@ external createImageBitmap18: (
external structuredClone: ('t, ~options: structuredSerializeOptions=?) => 't = "structuredClone"

/**
`fetch(string, init)`

Starts the process of fetching a resource from the network,
returning a promise that is fulfilled once the response is available.

```res
let response = await fetch("https://rescript-lang.org")
```

[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
*/
external fetch: (~input: request, ~init: requestInit=?) => Promise.t<response> = "fetch"
external fetch: (string, ~init: requestInit=?) => Promise.t<response> = "fetch"

/**
`fetch_withRequest(request, init)`

Starts the process of fetching a resource from the network,
returning a promise that is fulfilled once the response is available.

```res
let response = await fetch(myRequest)
```

[Read more on MDN](https://developer.mozilla.org/docs/Web/API/Window/fetch)
*/
external fetch2: (~input: string, ~init: requestInit=?) => Promise.t<response> = "fetch"
@send
external fetch_withRequest: (request, ~init: requestInit=?) => Promise.t<response> = "fetch"

/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/DedicatedWorkerGlobalScope/requestAnimationFrame)
Expand Down
9 changes: 9 additions & 0 deletions tests/Global__test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/Global__test.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
open WebAPI.Global

let response = await fetch("https://rescript-lang.org/")