-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(REST): allow options.query as URLSearchParams #4143
Conversation
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of expanding an instance of an URLSearchParams
into an array and then constructing URLSearchParams
again, Object.entries(options.query)
could be reduced into an array of [key, value]
where each value
is mapped out into [key, eachArrayValue]
(when it's an array). Something like this for example:
const query = Object.entries(options.query)
.filter(...)
.flatMap(([key, value]) =>
Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]
);
Then we can always pass an object as options.query
, for example: { foo: 'bar' }
/ { foo: ['bar, 'baz'] }
which would result into [ ['foo', 'bar'] ]
/ [ ['foo', 'bar'], ['foo', 'baz'] ]
. This seems somewhat more consistent, and I think it makes more sense to handle the query
within here rather than having to construct an URLSearchParams
over on the API method.
@izexi, sounds good! consider it done :) |
Please describe the changes this PR makes and why it should be merged:
This PR adds support for a request's
query
option to be either an object or URLSearchParams.This is necessary for #4142 to function. thanks vlad
Status
Semantic versioning classification: