0.1.1 • Published 8 years ago
@mck-p/obvi v0.1.1
Observable Server
Overview
@mck-p/obvi is a simple wrapper around http.createServer. It exposes a few helper methods and wraps each request inside of a Context object. The goal of this library is to be the lowest abstraction for more robust userland libraries.
Usage
const makeServer = require('@mck-p/obvi')
const {
_server, // http.creatServer() response
requests, // Observable of requests sent to server
start, // Start server listening on passed in port
stop // Stop server
} = makeServer({
port: 5000 // Port to listen for connections on
})
// We subscribe to all requests from this server
requests.subscribe((context) => {
console.log('I am responding to a request!')
})
// We create a stream of all post requests
const postRequests = requests.filter(({ request }) => request.method.toLowerCase() === 'post')
postRequests
// And we handle all post requests
.subscribe(({ response }) => response.send('You are sending me a post request!'))API
makeServer({ port?: number }):- Main export of module
- Returns a
Serverobject
Server
requests: Observable<Context>:- The main abstraction over
httprequests
- The main abstraction over
_server: http.Server:- The underlying
http.createServer()value
- The underlying
stop: () => http.Server:- How we stop listening for incoming requests
start: () => http.Server
Context
request: Request:- Our base abstraction over
http.IncomingMessage
- Our base abstraction over
response: Response:- Our base abstraction over
http.ServerResponse
- Our base abstraction over
Request
It is the underlying http.IncomingMessage with
url: Url:- Instead of
string, it returns this object withtrueas the second argument.
- Instead of
Response
response: http.ServerResponse:- The underlying
http.ServerResponseof the request
- The underlying
send: string => void:- An alias for
response.end
- An alias for
0.1.1
8 years ago
0.1.0
8 years ago
0.0.1
8 years ago
0.0.0-development.v2
8 years ago
0.0.0-development.v1
8 years ago
0.0.0-development
8 years ago