react-redux-fetch
react-redux-fetch copied to clipboard
Other fetch options
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
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.
Hi @ftcvlad - could you please explain the patch you made to requestBuilder? We have the same requirement to specify options on the fetch calls.
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.
Thanks for the info :+1: