Skip to content

Add support for URLSearchParams POST body - #304

Merged
dgraham merged 2 commits into
masterfrom
url-search-params
Mar 30, 2016
Merged

dgraham merged 2 commits into
masterfrom
url-search-params

Conversation

@dgraham

@dgraham dgraham commented Mar 30, 2016

Copy link
Copy Markdown
Contributor

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

mislav commented Mar 30, 2016

Copy link
Copy Markdown
Contributor

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
Comment thread fetch.js
this._bodyBlob = body
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
this._bodyFormData = body
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {

Copy link
Copy Markdown

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
Copy Markdown
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