react-redux-fetch icon indicating copy to clipboard operation
react-redux-fetch copied to clipboard

Other fetch options

Open ftcvlad opened this issue 7 years ago • 4 comments

Hi,

Is it possible to include other fetch options to request parameters?

For example, i need "credentials:include" and "mode:cors" for my fetch requests. For now I had to patch requestBuilder myself

ftcvlad avatar Feb 14 '18 19:02 ftcvlad

Hi @ftcvlad, it's indeed not possible now, only by replacing requestBuilder with your own implementation. It would be a nice enhancement though. I'll try to find some time to add that configuration option.

hirviid avatar Feb 15 '18 20:02 hirviid

Hi @ftcvlad - could you please explain the patch you made to requestBuilder? We have the same requirement to specify options on the fetch calls.

peterdutton avatar Oct 17 '18 08:10 peterdutton

Hi @peterdutton, you could do something like this:

import { container } from 'react-redux-fetch';

const originalRequestBuilder = container.getDefinition('requestBuilder').getArgument('build');

const customRequestBuilder = (url, config) => {
  const request = originalRequestBuilder(url, config);

  request.credentials = 'include';
  return request;
};

container.getDefinition('requestBuilder').replaceArgument('build', customRequestBuilder);

If you want to do more advanced stuff, you can copy the implementation in https://github.com/hirviid/react-redux-fetch/blob/master/src/utils/requestBuilder.js as a starting point and change the code where needed.

hirviid avatar Oct 18 '18 06:10 hirviid

Thanks for the info :+1:

peterdutton avatar Oct 18 '18 09:10 peterdutton