Skip to content

Update FetchAPI constructors #103

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
May 22, 2025
Merged

Conversation

stephanoskomnenos
Copy link
Contributor

No description provided.

Copy link
Collaborator

@nojaf nojaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, looks good!
One small nit, I would like to avoid the KV abbreviation.

/**
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#setting_headers)
*/
external fromKVArray: array<(string, string)> => headersInit = "%identity"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
external fromKVArray: array<(string, string)> => headersInit = "%identity"
external fromKeyValueArray: array<(string, string)> => headersInit = "%identity"


/**
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/URLSearchParams)
*/
@new
external make2: (~init: any=?) => urlSearchParams = "URLSearchParams"
external fromKVArray: array<(string, string)> => urlSearchParams = "URLSearchParams"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
external fromKVArray: array<(string, string)> => urlSearchParams = "URLSearchParams"
external fromKeyValueArray: array<(string, string)> => urlSearchParams = "URLSearchParams"


let h2 = Headers.fromDict(dict{"X-Vegetable": "Carrot"})

let h3 = Headers.fromKVArray([("X-Fruit", "Apple"), ("X-Vegetable", "Carrot")])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let h3 = Headers.fromKVArray([("X-Fruit", "Apple"), ("X-Vegetable", "Carrot")])
let h3 = Headers.fromKeyValueArray([("X-Fruit", "Apple"), ("X-Vegetable", "Carrot")])

params1->URLSearchParams.keys->Iterator.toArray->Array.forEach(Console.log)

let params2 = URLSearchParams.make3(~init="?foo=1&bar=b")
let params2 = URLSearchParams.fromKVArray([("foo", "1"), ("bar", "b")])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let params2 = URLSearchParams.fromKVArray([("foo", "1"), ("bar", "b")])
let params2 = URLSearchParams.fromKeyValueArray([("foo", "1"), ("bar", "b")])

@stephanoskomnenos
Copy link
Contributor Author

Thanks for your suggestion!

@stephanoskomnenos
Copy link
Contributor Author

How is Response.fromString("") comparing to Response.make(~body=BodyInit.fromString(""))?

@nojaf
Copy link
Collaborator

nojaf commented May 22, 2025

How is Response.fromString("") comparing to Response.make(~body=BodyInit.fromString(""))?

Hmm, you are suggesting to maybe reuse BodyInit?
Response.fromString("") seems more ergonomic.

@nojaf nojaf merged commit ef9aeac into rescript-lang:main May 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants