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

[Feature Request] Options query should be parsed recursively and allow custom formats #35

Open
Niels-NTG opened this issue Jun 12, 2019 · 1 comment

Comments

@Niels-NTG
Copy link
Contributor

Niels-NTG commented Jun 12, 2019

When supplying a request with an option object like this:

                {
                    page: {
                        page: this.currentPage,
                        itemsPerPage: this.itemsPerPage,
                    },
                    sort: this.sort
                }

nested objects like page aren't parsed like expected, resulting in an URL like /organisations?page=%5Bobject%20Object%5D&sort=id instead of /organisations?page[page]=1&page[itemsPerPage]=20&sort=id

I can think of 3 solutions to this issue:

  1. use a library like qs and make the formatting of the output configurable.
  2. Remove the getOptionsQuery method and let the API client deal with the parsing instead by passing the params to the .get method: return this.api.get(url, options). 👈
    get(path, options) {
        const params = qs.stringify(options, {
            arrayFormat: 'brackets',
            encode: false
        })
        path = `${path}?${params}`
        return APIClient.get(path)
    },
  1. Make the getOptionsQuery method overridable so people can replace it with their own parsing functions. Something like this:
reststateClient.getOptionsQuery = (optionsObject = {}) => {
    return qs.stringify(optionsObject, {
        arrayFormat: 'brackets',
        encode: false
    })
}
@Niels-NTG Niels-NTG changed the title Options query should be parsed recursively and allow custom formats [Feature Request] Options query should be parsed recursively and allow custom formats Jun 25, 2019
@CodingItWrong
Copy link
Contributor

FYI, this library will be unmaintained going forward.

If you need new features or fixes, I recommend forking the repo and making changes, or finding an alternate library that meets your needs.

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

No branches or pull requests

2 participants