Skip to content

Taxum / @taxum/core / middleware/from-fn / fromFn

Function: fromFn()

fromFn<Next, Request, Response>(f): FromFnLayer<Next, Request, Response>

Defined in: middleware/from-fn.ts:30

Creates a layer from a function.

Type Parameters

Next

Next extends AnyService

Request

Request

Response

Response

Parameters

f

FromFnClosure<Next, Request, Response>

Returns

FromFnLayer<Next, Request, Response>

Example

ts
import { fromFn } from "@taxum/core/middleware/from-fn";
import { m, Router } from "@taxum/core/routing";

const router = new Router()
    .route("/", m.get(() => "Hello World))
    .layer(fromFn((req, next) => {
        // do something with `req`

        const res = await next.invoke(req);

        // do something with `res`

        return res;
    }));