Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/malcolmyu/isom-fetch

A isomorphic fetch for SSR and koa
https://github.com/malcolmyu/isom-fetch

Last synced: 27 days ago
JSON representation

A isomorphic fetch for SSR and koa

Awesome Lists containing this project

README

        

# isom-fetch

[![Build Status](https://travis-ci.org/malcolmyu/isom-fetch.svg?branch=master)](https://travis-ci.org/malcolmyu/isom-fetch)

A isomorphic fetch for SSR and Koa.

## Use in server

```js
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

```js
import fetch from 'isom-fetch';

const fetch = fetch.create({
baseURL: '/api',
headers: {}
});

fetch.get(`/user/${id}`);
fetch.post(`/user`, id);
```