mirror of
https://github.com/fspc/workstand.git
synced 2026-09-17 09:01:39 -04:00
Load data with redux
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user