rr

rx-router

An Rx based http router

Showing:

Popularity

Downloads/wk

18

Maintenance

No Maintenance Data Available

Package

Dependencies

1

Size (min+gzip)

0.9KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Rx Router

A server http request router built with RxJS.

Example

var Rx           = require("rx");
var RxHttpServer = require("rx-http-server");
var router       = require("rx-router");

var defaultHandler = function(data) {
    data.result = "no match found";
    return Rx.Observable.fromArray([data]);
};

var rootHandler = function(data) {
    data.result = "hello from root";
    return Rx.Observable.fromArray([data]);
};

var regexHandler = function(data) {
    data.result = "hello from regex";
    return Rx.Observable.fromArray([data]);
};

var server = new RxHttpServer();
var routes = router(defaultHandler, {
    "GET": [
        ["/",           rootHandler],
        [/^\/test\/.+/, regexHandler]
    ]
});

server.requests.flatMap(routes).subscribe(function(data) {
    data.response.writeHead(200, {"Content-Type": "text/plain"});
    data.response.end(data.result);
});

server.listen(3000);

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100