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

Array format in query string parameters #9

Open
javierbrea opened this issue Jun 11, 2019 · 0 comments
Open

Array format in query string parameters #9

javierbrea opened this issue Jun 11, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@javierbrea
Copy link
Member

Currently, when passing an array to a query string parameter it is always stringified as a list separated by commas.

It is desirable that this behavior can be configured to use another array formats, such as in the query-string npm package

For doing this, a new configuration option called queryStringArrayFormat could be added:

import { Api } from "@xbyorange/mercury-api";

const myApi =  new Api("/foo-url", {
  queryStringArrayFormat: "none"
});

fooApi.query({
  queryString: { foo: [1, 2, 3] }
}).read();

//=> 'foo=1,2'

Available formats could be the same than in the query-string npm package:

  • 'bracket': Serialize arrays using bracket representation:
//=> 'foo[]=1&foo[]=2&foo[]=3'
  • 'index': Serialize arrays using index representation:
//=> 'foo[0]=1&foo[1]=2&foo[3]=3'
  • 'comma': Serialize arrays by separating elements with comma (default behavior until next major version for maintaining retrocompatibility):
//=> 'foo=1,2,3'
  • 'none': Serialize arrays by using duplicate keys (default behavior in next major version):
//=> 'foo=1&foo=2&foo=3'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant