isom-fetch
v1.1.1
Published
A isomorphic fetch for SSR and koa
Downloads
7
Readme
isom-fetch
A isomorphic fetch for SSR and Koa.
Use in server
import isomFetch from 'isom-fetch';
import router from '../router';
app.use(router);
app.use(function* (next) {
const location = this.originalUrl;
match({ routes, location }, (
error, redirectLocation, renderProps
) => {
const fetch = isomFetch.use(this, router);
// begin SSR
if (renderProps) {
render();
fetch.all(() => {
// SSR actually
render();
});
}
});
});
Use in client
import fetch from 'isom-fetch';
const fetch = fetch.create({
baseURL: '/api',
headers: {}
});
fetch.get(`/user/${id}`);
fetch.post(`/user`, id);