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

Support customization of query string serializer in redux-resource-xhr #178

Closed
whichsteveyp opened this issue Aug 10, 2017 · 3 comments
Closed
Labels
ecosystem extra This relates to something in the Redux Resource ecosystem, and not the core library enhancement A new feature that adds functionality to the library good first issue This is a great issue for someone who is new to contributing to Redux Resource

Comments

@whichsteveyp
Copy link
Contributor

One of my APIs that I proxy through my webserver actually requires a query string that looks something like this:

http://service/path/to/handler?id=1&id=2&id=3&etc...

If you look at the qs lib they allow for configuration of arrays in a few ways, like so:

qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'

It seems the current options I have are:

  1. qs-ify my URI prior to passing it in to the action-reactor
  2. transform it on the webserver layer before handing it off to the server

This is due to limitations of the existing qs options we can patch onto the xhr under-the-hood, like so:

const xhrOptions = {
    json: true,
    url: `/api/my/url`,
    qs: {id: ids},
  };

This produces an XHR to a URI that looks something like this by default:

/api/my/url&id=1,2,3

I spoke with @jmeas offline about this, and there's a few ways we can approach this, but wanted to post that here so we could capture the discussion and then once we figure out the desired changes (if any) we can reference it here.

Thoughts?

@jamesplease jamesplease added the question This issue describes a question that needs a resolution label Aug 10, 2017
@whichsteveyp
Copy link
Contributor Author

I know earlier we talked about both the impacts in 'over heard' for a flexible API from a maintenance and API surface area for users, but one thing we could consider adding is allowing qs here to be either:

  1. Something we can pass to our internal qs method and use to build a URI
  2. A function that can be invoked (possibly with other URI strings?) to handle the qs.stringify however users prefer.

Just some random thoughts on it - and I think you mentioned that approach awhile back too.

@jamesplease
Copy link
Owner

The API should mirror what's outlined here:

naugtur/xhr#160 (comment)

so that this lib is an easy transition to [email protected]

@jamesplease jamesplease added ecosystem extra This relates to something in the Redux Resource ecosystem, and not the core library enhancement A new feature that adds functionality to the library and removed question This issue describes a question that needs a resolution labels Aug 24, 2017
@jamesplease jamesplease changed the title QS, XHR, Action Creators, and more... Support customization of query string serializer in redux-resource-xhr Oct 1, 2017
@jamesplease jamesplease added the good first issue This is a great issue for someone who is new to contributing to Redux Resource label Oct 14, 2017
@jamesplease
Copy link
Owner

I'd be alright with merging just about any API that implements this. If it follows what xhr plans to add in v3, then that's awesome, but not a requirement. PRs welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem extra This relates to something in the Redux Resource ecosystem, and not the core library enhancement A new feature that adds functionality to the library good first issue This is a great issue for someone who is new to contributing to Redux Resource
Projects
None yet
Development

No branches or pull requests

2 participants