0.1.0 • Published 6 years ago
@express-love/functional-middleware v0.1.0
Installation
npm install @express-love/functional-middleware
Usage
functionalMiddleware
Creates an express middleware function that allows endpoints to be expressed
as a function returning a response value. The specified createResponse
function will be called and the response value that is returned will be sent
to the specified sendResponse
function.
Parameters
options
Object
Examples
const express = require('express');
const functionalMiddleware = require('@express-love/functional-middleware');
const sendResponse = (res, response) => res.status(response.status).send(response.body);
const apiHandler = (createResponse) => functionalMiddleware({ createResponse, sendResponse });
const app = express();
app.get('/api/examples', apiHandler(async (req) => {
await doSomething();
return { status: 200, body: 'hello world' };
}));
Returns Function An express middleware function.
0.1.0
6 years ago