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 support for URLSearchParams POST body #304

Merged
merged 2 commits into from
Mar 30, 2016
Merged

Conversation

dgraham
Copy link
Contributor

@dgraham dgraham commented Mar 30, 2016

Allows a URLSearchParams object to be serialized as a request body with a Content-Type: application/x-www-form-urlencoded header.

var params = new URLSearchParams()
params.append('user', 'hubot')
fetch('/test', {method: 'post', body: params})

Related:

Closes #296.

/cc @mislav @btd

@mislav
Copy link
Contributor

mislav commented Mar 30, 2016

Looks good!

@dgraham dgraham merged commit cff0ebb into master Mar 30, 2016
@dgraham dgraham deleted the url-search-params branch March 30, 2016 19:42
@@ -193,6 +194,8 @@
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
Copy link

Choose a reason for hiding this comment

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

Would this still work if the body came from another realm?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not. To be sure, one could perform search params serialization manually via toString() when passing it to fetch().

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It will be good to add URLSearchParams support
3 participants