Skip to content

Plugins

Routup is minimalistic by design. Plugins extend the framework with additional functionality that is not part of the core.

A plugin is an object with a name and an install method that receives the router instance.

Mounting

Mount a plugin globally:

typescript
router.use(myPlugin({ /* options */ }));

Mount a plugin on a specific path:

typescript
router.use('/api', myPlugin({ /* options */ }));

Writing a Plugin

Define a plugin as a factory function that returns a Plugin object:

typescript
import { defineCoreHandler } from 'routup';
import type { Plugin } from 'routup';

export type Options = {
    path?: string;
};

export function myPlugin(options: Options = {}): Plugin {
    const path = options.path || '/hello';

    return {
        name: 'myPlugin',
        install: (router) => {
            router.get(path, defineCoreHandler((event) => {
                return 'Hello from plugin!';
            }));
        }
    };
}

Using a Plugin

typescript
import { Router } from 'routup';
import { myPlugin } from '@routup/my-plugin';

const router = new Router();

router.use(myPlugin({ path: '/hello' }));

Ecosystem

Official plugins are available at GitHub.

NameDescription
assetsServe static files from a directory
basicBundle of body, cookie, and query plugins
bodyRead and parse the request body
cookieRead/write cookies
decoratorsClass, method, and parameter decorators
prometheusCollect and serve Prometheus metrics
queryParse URL query strings
rate-limitRate limit incoming requests
rate-limit-redisRedis adapter for rate-limit
swaggerServe Swagger/OpenAPI docs