concept AJAX call in category react
appears as: AJAX call, n AJAX call

This is an excerpt from Manning's book Redux in Action.
An implementation of fetchTasks that performs the AJAX call
Listing 5.13. Making the AJAX call – src/middleware/api.js
... const apiMiddleware = store => next => action => { const callApi = action[CALL_API]; if (typeof callApi === 'undefined') { return next(action); } const [requestStartedType, successType, failureType] = callApi.types; next({ type: requestStartedType }); return makeCall(callApi.endpoint).then( #1 response => next({ #2 type: successType, payload: response.data, }), error => next({ #3 type: failureType, error: error.message, }), ); }; export default apiMiddleware; #1 Passes the endpoint specified by the current action to makeCall #2 If the request succeeds, dispatches the success action type with the response. #3 If it fails, dispatches the failure type with an error message. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":11,\"ch\":48},{\"line\":11,\"ch\":50}],[{\"line\":27,\"ch\":0},{\"line\":27,\"ch\":2}],[{\"line\":13,\"ch\":48},{\"line\":13,\"ch\":50}],[{\"line\":28,\"ch\":0},{\"line\":28,\"ch\":2}],[{\"line\":18,\"ch\":48},{\"line\":18,\"ch\":50}],[{\"line\":29,\"ch\":0},{\"line\":29,\"ch\":2}]]"} !@%STYLE%@!