Load data with redux

This commit is contained in:
Drew Larson
2017-05-23 19:30:44 -06:00
parent e6b189edd8
commit 8f9d1c3663
13 changed files with 427 additions and 213 deletions
@@ -0,0 +1,28 @@
import fetch from 'isomorphic-fetch';
const checkStatus = (response) => {
if (response.status >= 200 && response.status < 300) {
return response;
}
const error = new Error(response.statusText);
error.response = response;
throw error;
};
const parseJson = response => response.json();
const Api = {
fetchBikes() {
return fetch('/api/v1/bikes/', {
credentials: 'same-origin',
})
.then(checkStatus)
.then(parseJson)
.then(data => data)
.catch((error) => {
console.log('request failed', error);
});
},
};
export default Api;