In some http clients, e.g. jQuery.ajax, it's possible to not just put the params in the URL but an object. The client will mix/concat the params into the URL later. Is that possible to give params independently like
fetch("foo.json" {
method: "get",
params: {
param1: "value1",
param2: "value2",
}
}).then(response => response.json())
to come up with a URL /foo.json¶m1=value1¶m2=value2?
Also, sometimes the params may be longer than the length limitation, so that some APIs accept GET requests with a body of parameters. So I don't understand the reason fetch couldn't _GET_ with the body like
fetch("foo.json" {
method: "get",
body: {
param1: "value1",
param2: "value2",
}
}).then(response => response.json())
Will these be behaviors allowed in the future? Maybe I can submit a pull request for these.
It's best to ask for this support at the https://github.com/whatwg/fetch specification repository.
URLSearchParams is accepted as a body value, but it's only supported by Firefox right now.
@dgraham That is, if we create a polyfill for URLSearchParams it should work with this fetch polyfill?
@dgraham not exactly accepted. fetch polyfill is still complaining TypeError: Body not allowed for GET or HEAD requests

How is this solved today?
Query parameters may be encoded natively with encodeURIComponent or with jQuery.param.
Most helpful comment
Query parameters may be encoded natively with encodeURIComponent or with jQuery.param.