Headers Override

Last updated 6 months ago
  • You can configure headers globally:

export const {types, actions, reducers} = createResource({
name: 'user',
url: 'https://foo.com/users/:id',
headers: {
'X-Custom-Header': 'foobar'
}
});
  • You may want to globally update default headers at run time (eg. you received a new JWT):

import {defaultHeaders} from 'redux-rest-resource';
const jwt = 'xvDjirE9MCIi800xMxi4EKeTm8e9FUBR';
Object.assign(defaultHeaders, {Authorization: `Bearer ${jwt}`});
  • You can also configure headers for a specific action:

export const {types, actions, reducers} = createResource({
name: 'user',
url: 'https://foo.com/users/:id',
actions: {
update: {
headers: {
'X-Custom-Header': 'foobar'
}
}
}
});
  • Or as an one-time override at action call-time:

actions.updateUser({firstName: 'Olivier'}, {headers: {Authorization: `Bearer ${jwt}`}});