Skip to content
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

add url params to fetch #233

Merged
merged 3 commits into from
Jan 6, 2024
Merged

add url params to fetch #233

merged 3 commits into from
Jan 6, 2024

Conversation

kotontrion
Copy link
Contributor

this PR adds a params to the options of fetch. These two are equivalent:

Utils.fetch('https://wttr.in/?format=3')
const options = {
  params: { format: 3 }
}
Utils.fetch('https://wttr.in/', options)

This is especially useful, if the params are created dynamically, as the users won't have to handle encoding themself.
This is not part of the web fetch api, but i think this is still useful, as unlike the web, there is no URLSearchParamsin gjs.
I did some testing on this and this is compliant with the url scheme.

@kotontrion kotontrion marked this pull request as draft December 31, 2023 16:05
@kotontrion
Copy link
Contributor Author

the param will be parsed as follows:
primitive types => key=value
arrays => key=value1&key=value2
objects => key=[JSON representation of object]

the way arrays is parsed is commonly accepted, but there is no standardized way to pass objects, so i just pass the object as json, otherwise it would be passed as [Object object], which is definitely wrong.

@kotontrion kotontrion marked this pull request as ready for review January 1, 2024 08:15
@Aylur Aylur merged commit 9aac2aa into Aylur:main Jan 6, 2024
2 checks passed
@kotontrion kotontrion deleted the add/urlParams branch February 19, 2024 07:40
gorsbart pushed a commit to gorsbart/ags that referenced this pull request Feb 28, 2024
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