🔋 RxJS Observable wrapped around the WHATWG Fetch API.
RxJS Observable wrapped around the WHATWG Fetch API.
$ yarn add observable-fetch
Alternatively using npm:
$ npm i observable-fetch --save
This library is especially built to be complementary to redux-observable;
import fetch from 'observable-fetch';
// action creators
const fetchUser = username => ({ type: FETCH_USER, payload: username });
const fetchUserFulfilled = payload => ({ type: FETCH_USER_FULFILLED, payload });
// epic
const fetchUserEpic = action$ =>
action$.ofType(FETCH_USER)
.mergeMap(action =>
fetch(`https://api.github.com/users/${action.payload}`)
.map(response => fetchUserFulfilled(response))
);
// later...
dispatch(fetchUser('torvalds'));
MIT © Robin van der Vleuten