1.3.0 • Published 3 years ago

middleify v1.3.0

Weekly downloads
39
License
ISC
Repository
github
Last release
3 years ago

Middleify

A highly opinionated, typed, clean and reusable middleware library for TypeScript.

Write small, reusable middleware components and chain them together to build a route handler. To maximise reuse and portability, well written routes should only interact with framework specific arguments in the first and last middlewares.

Middleify comes with built-in helpers for common actions such as http responses, mapping property names, and error handling.

Example

// app.ts
import express, { query } from 'express';
import { route, respondWith } from 'middleify/express';
import { exampleMiddleware } from './exampleMiddleware';

const app = express()
    
    .get(
        '/example',
        route(
            (context, req) => ({
                property: 'test',
                queryParameter: req.query.parameter,
            }),
            exampleMiddleware,
            respondWith('result'),
        )
    );

// exampleMiddleware.ts
export const exampleMiddleware = ({ property, queryParameter }: Context) => ({
    result: `${property}: ${queryParameter}`
});

type Context = {
    property: string;
    queryParameter: string;
}

Responses

TODO

Mapping

TODO

Error Handling

TODO

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago