koa-router-rx
v0.4.0
Published
Reactive router middleware for koa
Downloads
18
Maintainers
Readme
koa-router-rx
Router middleware for koa 2.x based on koa-router and rxjs.
Introduction
koa-router-rx is an extension of koa-router that supports functions of RxJS Observables instead of regular middleware. Those functions are called "Epics", a concept directly inspired by redux-observable.
An Epic is a function that takes an Observable argument and returns an Observable:
(observable: Observable<A>) => Observable<B>
Usage
koa-router-rx works just like koa-router, except that it expects an Epic instead of a koa-style middleware:
import Koa from 'koa'
import RxRouter from '../lib'
const router = new RxRouter()
router.get('/hello', observable => observable.mapTo('Hello!'))
app.use(router.routes())
app.listen(3333)
See the example for more details.
Caveats
- Named routes are not supported.
- Passing multiple Epics is not supported.