Backstage
    Preparing search index...

    Typed Express router based on an OpenAPI 3.1 spec.

    interface ApiRouter<Doc extends RequiredDoc> {
        all: DocRequestMatcher<Doc, ApiRouter<Doc>, "all">;
        checkout: IRouterMatcher<ApiRouter<Doc>>;
        connect: IRouterMatcher<ApiRouter<Doc>>;
        copy: IRouterMatcher<ApiRouter<Doc>>;
        delete: DocRequestMatcher<Doc, ApiRouter<Doc>, "delete">;
        get: DocRequestMatcher<Doc, ApiRouter<Doc>, "get">;
        head: DocRequestMatcher<Doc, ApiRouter<Doc>, "head">;
        link: IRouterMatcher<ApiRouter<Doc>>;
        lock: IRouterMatcher<ApiRouter<Doc>>;
        "m-search": IRouterMatcher<ApiRouter<Doc>>;
        merge: IRouterMatcher<ApiRouter<Doc>>;
        mkactivity: IRouterMatcher<ApiRouter<Doc>>;
        mkcol: IRouterMatcher<ApiRouter<Doc>>;
        move: IRouterMatcher<ApiRouter<Doc>>;
        notify: IRouterMatcher<ApiRouter<Doc>>;
        options: DocRequestMatcher<Doc, ApiRouter<Doc>, "options">;
        patch: DocRequestMatcher<Doc, ApiRouter<Doc>, "patch">;
        post: DocRequestMatcher<Doc, ApiRouter<Doc>, "post">;
        propfind: IRouterMatcher<ApiRouter<Doc>>;
        proppatch: IRouterMatcher<ApiRouter<Doc>>;
        purge: IRouterMatcher<ApiRouter<Doc>>;
        put: DocRequestMatcher<Doc, ApiRouter<Doc>, "put">;
        report: IRouterMatcher<ApiRouter<Doc>>;
        search: IRouterMatcher<ApiRouter<Doc>>;
        stack: ILayer[];
        subscribe: IRouterMatcher<ApiRouter<Doc>>;
        trace: IRouterMatcher<ApiRouter<Doc>>;
        unlink: IRouterMatcher<ApiRouter<Doc>>;
        unlock: IRouterMatcher<ApiRouter<Doc>>;
        unsubscribe: IRouterMatcher<ApiRouter<Doc>>;
        use: IRouterHandler<ApiRouter<Doc>, string> & IRouterMatcher<
            ApiRouter<Doc>,
            any,
        >;
        param(name: string, handler: RequestParamHandler): this;
        param(
            callback: (name: string, matcher: RegExp) => RequestParamHandler,
        ): this;
        route<T extends string>(prefix: T): IRoute<T>;
        route(prefix: PathParams): IRoute;
        (
            req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>,
            res: Response<any, Record<string, any>>,
            next: NextFunction,
        ): void;
    }

    Type Parameters

    Hierarchy

    • Router
      • ApiRouter
    • Parameters

      • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
      • res: Response<any, Record<string, any>>
      • next: NextFunction

      Returns void

    Index

    Properties

    Special-cased "all" method, applying the given route path, middleware, and callback to every HTTP method.

    checkout: IRouterMatcher<ApiRouter<Doc>>
    connect: IRouterMatcher<ApiRouter<Doc>>
    copy: IRouterMatcher<ApiRouter<Doc>>
    delete: DocRequestMatcher<Doc, ApiRouter<Doc>, "delete">
    link: IRouterMatcher<ApiRouter<Doc>>
    lock: IRouterMatcher<ApiRouter<Doc>>
    "m-search": IRouterMatcher<ApiRouter<Doc>>
    merge: IRouterMatcher<ApiRouter<Doc>>
    mkactivity: IRouterMatcher<ApiRouter<Doc>>
    mkcol: IRouterMatcher<ApiRouter<Doc>>
    move: IRouterMatcher<ApiRouter<Doc>>
    notify: IRouterMatcher<ApiRouter<Doc>>
    options: DocRequestMatcher<Doc, ApiRouter<Doc>, "options">
    patch: DocRequestMatcher<Doc, ApiRouter<Doc>, "patch">

    post

    propfind: IRouterMatcher<ApiRouter<Doc>>
    proppatch: IRouterMatcher<ApiRouter<Doc>>
    purge: IRouterMatcher<ApiRouter<Doc>>
    report: IRouterMatcher<ApiRouter<Doc>>
    search: IRouterMatcher<ApiRouter<Doc>>
    stack: ILayer[]

    Stack of configured routes

    subscribe: IRouterMatcher<ApiRouter<Doc>>
    trace: IRouterMatcher<ApiRouter<Doc>>
    unlink: IRouterMatcher<ApiRouter<Doc>>
    unlock: IRouterMatcher<ApiRouter<Doc>>
    unsubscribe: IRouterMatcher<ApiRouter<Doc>>
    use: IRouterHandler<ApiRouter<Doc>, string> & IRouterMatcher<
        ApiRouter<Doc>,
        any,
    >

    Methods

    • Map the given param placeholder name(s) to the given callback(s).

      Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code,

      The callback uses the samesignature as middleware, the only differencing being that the value of the placeholder is passed, in this case the id of the user. Once the next() function is invoked, just like middleware it will continue on to execute the route, or subsequent parameter functions.

       app.param('user_id', function(req, res, next, id){
         User.find(id, function(err, user){
           if (err) {
             next(err);
           } else if (user) {
             req.user = user;
             next();
           } else {
             next(new Error('failed to load user'));
           }
         });
       });
      

      Parameters

      • name: string
      • handler: RequestParamHandler

      Returns this

    • Alternatively, you can pass only a callback, in which case you have the opportunity to alter the app.param()

      Parameters

      • callback: (name: string, matcher: RegExp) => RequestParamHandler

      Returns this

      since version 4.11

    • Type Parameters

      • T extends string

      Parameters

      • prefix: T

      Returns IRoute<T>

    • Parameters

      • prefix: PathParams

      Returns IRoute