erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12k stars 2.5k forks source link

How can i call real API in loadInfo.js #1277

Closed pengzhanlee closed 8 years ago

pengzhanlee commented 8 years ago

Hi All,

in api/actions/loadInfo.js

return new Promise((resolve) => {

    resolve({
        message: 'This came from the api server',
        time: Date.now()
    });
});

how can i call real api here instead of return a json ? such as:

return fetch('http://api-server.com/someapi/');

jdosullivan commented 8 years ago

You'd need to modify the ApiClient.js. By default it calls a function called formatUrl which appends the '/api/' in front of any value it is passed. You;d need to provide a way to override that.

Can you say more as to what you are trying to do? Are you trying to call an external api?

pengzhanlee commented 8 years ago

thanks for taking the time to answer my questions.

I modified the formatUrl function in ApiClient.js function formatUrl(path) { return 'http://api.com/' + path; }

And call the api in src/redux/modules/someModule return client.get('/some/api');

it works now!

It seems like the files in api/actions/foo/bar are used for mock data?

one another question is should I define both action add reducer in redux/modules/someModule?