fun-chain-dispatch
v0.3.0
Published
HTTP dispatch functions to use with fun-chain
Downloads
1
Readme
Builds functions that fit into a chain intended to be used with node's
http.createServer
method.
E.g.
http.createServer(chain(
[ dispatch('get', '/foo', serveFoo)
, dispatch('get', '/bar', serveBar)
, dispatch(matchesStaticFile, serveStaticFile)
, dispatch(serveNotFound)
]))
"Porcelain" API:
dispatch('get', '/foo', foo)
dispatch(matcherFn, handler)
dispatch(handler)
"Plumbing" API:
dispatch.ifMatchElseNext(
dispatch.matchers.forMethodAndPathname('get', '/foo')
, serveFoo )
dispatch.ifMatchElseNext(
matchesStaticFile
, serveStaticFile )
dispatch.ifMatchElseNext(
dispatch.matchers.any
, serveNotFound )
Todo:
- Support sinatra-style url patterns and url "params" extraction, probably using the path-to-regexp module