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. Basics

Resources

  • Resources are ready-to-use store modules, simple javascript objects with the following structure:

{
  types, actions, reducers, rootReducer;
}

@NOTE: reducers is currently also exposing the root reducer, but using rootReducer is the recommended way forward. Will break once 1.0 is reached.

  • Resources are the ready-to-use abstraction for your REST related needs.

  • They can be created with a simple factory function:

import {createResource} from 'redux-rest-resource';

const hostUrl = 'https://api.mlab.com:443/api/1/databases/sandbox/collections';
const apiKey = 'xvDjirE9MCIi800xMxi4EKeTm8e9FUBR';

export const {types, actions, rootReducer} = createResource({
  name: 'user',
  url: `${hostUrl}/users/:id?apiKey=${apiKey}`
});

Options

Option name

Type

Description

name

String

Actual name of the resource (required)

url

Function/String

Actual url of the resource (required)

pluralName

String

Plural name of the resource (optional)

actions

Object

Action extra options, merged with defaults (optional)

export const {types, actions, rootReducer} = createResource({
  name: 'user',
  url: `${hostUrl}/users/:id?apiKey=${apiKey}`,
  credentials: 'include',
  headers: {'X-Custom-Header': 'Some static header'}
});
PreviousBasicsNextActions

Last updated 6 years ago

You can also pass any to set a global default.

action related option