I am trying to request an API without ajax call (why would I import the whole library for simply making an ajax call?).
So I decided to follow the fetch function flow as it is described in the Redux doc (which I migrate with last week).
import fetch from 'isomorphic-fetch'
Thus, I have this short function:
export function fetchPosts(value) {
return dispatch => {
dispatch(requestPosts(value))
return fetch(Config.serverUrl + '/' + value, {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
Authorization: Config.authorizationToken
},
})
.then(response => response.json())
.then(json => dispatch(receivePosts(value, json)))
};
};
but when I do a console.log in this next step function:
function receivePosts(value, json) {
console.log(json);
return {
type: RECEIVE_POSTS,
value,
posts: json.data.children.map(child => child.data)
};
};
I can see that my json is an empty object.
The network return this:
General:
Request URL:https://shelob-v2.dev.blippar.com/v2/categories
Request Method:OPTIONS
Status Code:200 OK
Remote Address:52.25.79.166:443
Header:
Access-Control-Allow-Headers:Authorization, Content-Type, X-Pouet-UniqueID, X-Pouet-UniqueRunID
Access-Control-Allow-Methods:PATCH, PUT, DELETE
Access-Control-Allow-Origin:*
Content-Length:0
Content-Type:text/plain; charset=utf-8
Date:Wed, 27 Apr 2016 14:14:36 GMT
Am I doing something definitely wrong with it?