Redux Rest Resource
  • Read Me
  • Usage
    • Quickstart
  • Basics
    • Resources
    • Actions
    • Reducers
    • Types
  • Examples
    • Actions
  • Advanced
    • Custom Actions
    • Pure Actions
    • Single Action Helper
    • Headers Override
    • Transform Response
    • Assign Update Response
    • Resource Combination
    • Custom Promise
    • Custom fetch
  • Defaults
    • Actions
    • Headers
    • State
  • Changelog
Powered by GitBook
On this page
  1. Advanced

Headers Override

  • 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}`}});
PreviousSingle Action HelperNextTransform Response

Last updated 6 years ago