https://github.com/mfellner/koa-router-rx
Reactive router middleware for koa
https://github.com/mfellner/koa-router-rx
koa rxjs
Last synced: about 1 year ago
JSON representation
Reactive router middleware for koa
- Host: GitHub
- URL: https://github.com/mfellner/koa-router-rx
- Owner: mfellner
- License: mit
- Created: 2016-12-05T17:12:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-05T11:41:53.000Z (over 9 years ago)
- Last Synced: 2024-10-12T00:23:54.254Z (over 1 year ago)
- Topics: koa, rxjs
- Language: JavaScript
- Size: 95.7 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-router-rx [](https://badge.fury.io/js/koa-router-rx) [](https://travis-ci.org/mfellner/koa-router-rx) [](https://coveralls.io/github/mfellner/koa-router-rx?branch=master)
Router middleware for [koa 2.x](https://github.com/koajs/koa/tree/v2.x) based on [koa-router](https://github.com/alexmingoia/koa-router) and [rxjs](https://github.com/ReactiveX/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](https://github.com/redux-observable/redux-observable).
An Epic is a function that takes an Observable argument and returns an Observable:
```javascript
(observable: Observable) => Observable
```
### Usage
koa-router-rx works just like koa-router, except that it expects an Epic instead of a koa-style middleware:
```javascript
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](example) for more details.
#### Caveats
* [Named routes](https://github.com/alexmingoia/koa-router/tree/master/#named-routes) are not supported.
* Passing [multiple Epics](https://github.com/alexmingoia/koa-router/tree/master/#multiple-middleware) is not supported.