diff --git a/src/apis/news.api.js b/src/apis/news.api.js new file mode 100644 index 0000000..515ac11 --- /dev/null +++ b/src/apis/news.api.js @@ -0,0 +1,11 @@ +export const simpleFetch = (url, onSuccess, onError) => fetch(url) + .then( + successResponse => successResponse.json(), + errorResponse => errorResponse.json() + ); + +export const UserProfileAPI = { + + byId: userId => simpleFetch(`https://hacker-news.firebaseio.com/v0/user/${userId}.json`) + +}; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 64b8f1a..80c9f3e 100644 --- a/src/index.js +++ b/src/index.js @@ -9,7 +9,12 @@ import Search from './components/Search/Search.component'; import NewsListTable from './components/NewsList/NewsListTable'; import CurrentDetails from './components/NewsDetails/CurrentDetails'; import UserProfileContainer from './components/UserProfile/UserProfileContainer'; +import { UserProfileAPI } from './apis/news.api'; +// Network request example (no redux) +UserProfileAPI.byId('mudil').then( + successResponse => console.log('success:', successResponse), + errorResponse => console.log('error:', errorResponse)); ReactDOM.render(