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

Arrays in query strings with cross-fetch #421

Open
thomsonbw opened this issue Sep 9, 2021 · 5 comments · May be fixed by #453
Open

Arrays in query strings with cross-fetch #421

thomsonbw opened this issue Sep 9, 2021 · 5 comments · May be fixed by #453

Comments

@thomsonbw
Copy link

"request" used the "qs" query string manipulation package and exposed its options in the requestOptions object. One of these, the "arrayFormat" setting, supported a variety of formats for an array parameter { a: [ "b", "c"] }
'indices' a[0]=b&a[1]=c (the default)
'brackets' a[]=b&a[]=c
'repeat' a=b&a=c
'comma' a=b,c

With the switch to cross-fetch this flexibility was lost, as query parameters are handled by resolver_builder code that only implements the first format.

@eokoneyo
Copy link
Contributor

@thomsonbw I've also stumbled on this problem, the unfortunate issue is there is no standard way of handling arrays in query strings, there's a whole discussion about this here https://stackoverflow.com/questions/6243051/how-to-pass-an-array-within-a-query-string. I wonder if it might make sense to have a config that allows the end user to specify how they'd like their arrays processed

@thomsonbw
Copy link
Author

@eokoneyo we effectively had a config option before cross-fetch. You could set the arrayFormat in the o2g requestOptions object and it would be passed through to the underlying package, but the current code doesn't provide similar flexibility.

@Alan-Cha
Copy link
Collaborator

@thomsonbw Sorry for the very late reply. I'm also sorry that this functionality was lost. I'll try to look into this but if any of you have suggestions on how this could be resolved, I'd love to know.

@DanailPenev DanailPenev linked a pull request Apr 2, 2022 that will close this issue
@DanailPenev
Copy link

@thomsonbw, I have opened a Pull request that adds an option for one of the other formats #453

@nicolasparada
Copy link

It's true that there are many ways to define arrays in query strings, but URLSearchParams API uses the "repeat" format:

const q = new URLSearchParams()
q.append("test", "one")
q.append("test", "two")
q.append("test", "three")
q.toString() === "test=one&test=two&test=three"

It should at the very least support that.

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 a pull request may close this issue.

5 participants