MCPcopy
hub / github.com/reduxjs/redux / callApi

Function callApi

examples/real-world/src/middleware/api.js:23–42  ·  view source on GitHub ↗
(endpoint, schema)

Source from the content-addressed store, hash-verified

21// Fetches an API response and normalizes the result JSON according to schema.
22// This makes every API response have the same shape, regardless of how nested it was.
23const callApi = (endpoint, schema) => {
24 const fullUrl = (endpoint.indexOf(API_ROOT) === -1) ? API_ROOT + endpoint : endpoint
25
26 return fetch(fullUrl)
27 .then(response =>
28 response.json().then(json => {
29 if (!response.ok) {
30 return Promise.reject(json)
31 }
32
33 const camelizedJson = camelizeKeys(json)
34 const nextPageUrl = getNextPageUrl(response)
35
36 return Object.assign({},
37 normalize(camelizedJson, schema),
38 { nextPageUrl }
39 )
40 })
41 )
42}
43
44// We use this Normalizr schemas to transform API responses from a nested form
45// to a flat form where repos and users are placed in `entities`, and nested

Callers 1

api.jsFile · 0.85

Calls 1

getNextPageUrlFunction · 0.85

Tested by

no test coverage detected