Create Express middleware using Futures from Fluture.
Allows for the definition of pure functions to be used as Express
middleware. This has benefits for testing and developer sanity.
Another benefit of this particular approach, where every middleware is
wrapped individually, is that it plays nicely with existing Express
middleware, and they can be used interchangably.
Usage
Node
$ npm install --save fluture-express
On Node 12 and up, this module can be loaded directly with import or
require. On Node versions below 12, require or the esm-loader can
be used.
Deno and Modern Browsers
You can load the EcmaScript module from various content delivery networks:
For a more in-depth example, see the example directory.
Documentation
Pseudo types
Req
The Express Request object.
Res a
The Express Response object with a locals property of type a.
The Response type
Fluture-Express mutates the response object for you, based on a
specification of what the response should be. This specification is
captured by the Response sum-type.
Creates a streamed response given a mime type and a Future that produces
a Readable Stream when consumed. The Future is expected to produce a new
Stream every time it's consumed, or if it can't, reject with a value that
your Express error handler can handle.
Indicates a response to be rendered using a template. The first argument
is the path to the template file, and the second is the data to inject into
the template. This uses Express' render method under the hood, so you can
configure it globally with app.set ('view engine', engine) and
app.set ('views', path).
Takes a function that returns a Future of a Response, and returns
an Express middleware that uses the returned structure to make the
appropriate mutations to the res.