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

Actions

  • create:

const createBody = {firstName: 'Olivier'};
const actionOpts = {query: {foo: 'bar'}};
actions.createUser(createBody, actionOpts);
// Will POST `createBody` to localhost:9000/api/users?foo=bar
  • fetch:

const actionOpts = {query: {foo: 'bar'}};
const fetchContext = null;
// fetchContext could be used as an object to resolve extra url parameters (eg. localhost:9000/api/:version/users/:id)
actions.fetchUsers(fetchContext, actionOpts);
// Will GET localhost:9000/api/users?foo=bar
  • update:

const updateBody = {id: '5925b7f7d9808600076ce557', firstName: 'Olivia'};
const actionOpts = {query: {foo: 'bar'}};
actions.updateUser(updateBody, actionOpts);
// Will PATCH updateBody to localhost:9000/api/users/5925b7f7d9808600076ce557?foo=bar
  • get:

const getContext = {id: '5925b7f7d9808600076ce557'};
// const getContext = '5925b7f7d9808600076ce557' would also work
const actionOpts = {query: {foo: 'bar'}};
actions.getUser(getContext, actionOpts);
// Will GET localhost:9000/api/users/5925b7f7d9808600076ce557?foo=bar
  • delete:

const deleteContext = {id: '5925b7f7d9808600076ce557'};
// const deleteContext = '5925b7f7d9808600076ce557' would also work
const actionOpts = {query: {foo: 'bar'}};
actions.deleteUser(getContext, actionOpts);
// Will DELETE localhost:9000/api/users/5925b7f7d9808600076ce557?foo=bar
PreviousExamplesNextAdvanced

Last updated 6 years ago

List of

all available options