-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from rescript-lang/fetch-with-options
Add fetch with headers and body sample
- Loading branch information
Showing
10 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
open FileAPI | ||
open FetchAPI | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromString: string => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromArrayBuffer: ArrayBuffer.t => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromTypedArray: TypedArray.t<'t> => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromDataView: DataView.t => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromBlob: blob => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromFile: file => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromURLSearchParams: urlSearchParams => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromFormData: formData => bodyInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_a_body) | ||
*/ | ||
external fromReadableStream: readableStream<'t> => bodyInit = "%identity" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open FetchAPI | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_headers) | ||
*/ | ||
external fromDict: dict<string> => headersInit = "%identity" | ||
|
||
/** | ||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_headers) | ||
*/ | ||
external fromHeaders: headers => headersInit = "%identity" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
open WebAPI.Global | ||
|
||
let response = await fetch("https://rescript-lang.org/") | ||
|
||
let response2 = await fetch( | ||
"https://rescript-lang.org/", | ||
~init={ | ||
headers: HeadersInit.fromDict( | ||
dict{ | ||
"Content-Type": "application/json", | ||
"Authorization": "Bearer token", | ||
}, | ||
), | ||
body: BodyInit.fromString(`secret=foo&response=bar`), | ||
}, | ||
) |