Skip to content

Conversation

@bertho-zero
Copy link

No description provided.

@bertho-zero bertho-zero changed the title use qs style by default for object params use qs style by default for params May 26, 2018
@bertho-zero
Copy link
Author

To keep the current behavior it will be necessary to use the paramsSerializer: 'simple' option. (depth arrays of 1, object json.stringified, skip null values)

If you just want to use brackets you can use the paramsSerializer: 'brackets' option.

The default formatting is now more complete and corresponds to qs.

The ideal would be to be able to remove the compatibility options and return to the documentation of a library as qs to use paramsSerializer as soon as the configuration is no longer the default one.

@bertho-zero
Copy link
Author

When an object is passed as paramsSerializer, it must be passed as options to encodeParams.

And we should add the option arrayFormat: 'repeat' (to fix #1443 like qs)

axios.get(
  "/url",
  { params: { a: ["b", "c"] } },
  { paramsSerializer: { arrayFormat: "indices" } }
);
// '/url?a[0]=b&a[1]=c'

axios.get(
  "/url",
  { params: { a: ["b", "c"] } },
  { paramsSerializer: { arrayFormat: "brackets" } }
);
// '/url?a[]=b&a[]=c'

axios.get(
  "/url",
  { params: { a: ["b", "c"] } },
  { paramsSerializer: { arrayFormat: "repeat" } }
);
// '/url?a=b&a=c'

@jasonsaayman
Copy link
Member

On this I don't think this should be implement as mentioned previously if you'd like to use another format, you can set a custom paramsSerializer as follows:

axios.defaults.paramsSerializer: function(params) {
  // return a query string
}

Using the qs library:

axios.defaults.paramsSerializer: function(params) {
  return qs.stringify(params, { indices: false }); // param=value1&param=value2
}

@axios axios locked and limited conversation to collaborators May 27, 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.

3 participants