0.2.0 • Published 8 years ago
observable-server v0.2.0
Observable Server
Like Express but with observables
Usage
import createServer from 'observable-server'
// OR
const createServer = require('observable-server')
const server = createServer()
server
.on({ url: '/users', method: 'post' })
.subscribe(({ request, resposne }) => { /* ... */ })API
createServer is the only export from this package. It is a function that takes an options object and returns a ServerInterface, both of which are defined below.
options: The options for our serverport: The port to listen onpre: An HoF that will be givenRouteOptionsand return an rxjslettablefunction to run before each route handler
ServerInterface: The interface for our server streamon: A function that, given aRouteOptionsshape, returns an observableRouteOptionsurl: An express-style url to match onmethod: The HTTP method to listen on or'*'orundefinedfor all methods- Any other values that are expected by a
prefor itsrouteOptionsHof function.
For a full demo, check out ./demo.js or after installing this locally, run npx nodemon demo.js and send requests to the server.