fetch

Methods

(inner) fetchCallback(func) → {function}

Returns a function that passes the value.data property expected fetch result to the given callback function

Parameters:
Name Type Description
func function

the callback to pass data to

Source:
See:
  • tests

Returns:

a function handles status codes appropriately and delivers the value.data property to its callback

Type
function
Example
import { sum } from 'ramda'

const apiResponse = {
  status: 200,
  value: {
    data: {
      numbers: [1, 2, 3]
    },
    meta: {
      numbers: [1, 2, 3]
    },
  },
}

const addNumbers = data => sum(data.numbers)
const addNumbersCallback = fetchCallback(addNumbers)

addNumbersCallback(apiResponse)
//=> 6

const addNumbersWithMeta = (data, meta) => sum([...data.numbers, ...meta.numbers])
const addNumbersWithMetaCallback = fetchCallback(addNumbersWithMeta)

addNumbersWithMetaCallback(apiResponse)
//=> 12

Type Definitions

FetchAction

Redux action object compatible with redux-effects-fetch with a type of 'EFFECT_FETCH', and a payload that describes a fetch call.

Type:
  • Object
Properties:
Name Type Description
url String

the request url for fetch call

params ParamsObject

the request params for fetch call

Source:

ParamsObject

A standard fetch request params object

Type:
  • Object
Properties:
Name Type Description
params.body Object

data used in post or put request

params.method String

rest verb 'GET', 'POST' etc...

params.headers Object

headers object

Source: