FusionFusion

Router

Register class-based APIs with route / router in Node.js

Overview

Decorate a FusionBaseApi subclass with route(...) (or router). Registration happens when the module is imported — import it from main.ts before listen().

import { FusionBaseApi, route, status } from "fusion-framework";

export const ItemModule = route("/api/[module]/{id}", {
  tags: ["items"],
  desc: "Items by id",
})(
  class ItemModule extends FusionBaseApi {
    get() {
      return this.response({ id: this.params.id }, status.HTTP_SUCCESS);
    }
  },
);

Path params are read from this.params (strings). Coerce with coerceParam if needed — Node does not bind handler signatures like Python.

route vs router

SymbolRole
route(path, options?)Primary — path + Swagger metadata + middleware / roles
router(path, options?)Same function (alias)

Path templates

TokenMeaning
Static textExact segment
[module]Class name stem, lowercased, Module suffix stripped
{name}Dynamic path param → this.params.name
route("api/[module]/{id}")(class ProductModule extends FusionBaseApi { ... });
// → /api/product/{id}

version: "v1" prefixes the resolved path: /v1/api/product/....

Options

OptionPurpose
tags, desc, title, deprecatedOpenAPI metadata (when enabled)
versionPath prefix
middlewareRoute-only middleware list
rolesAppends requireRoles(...)
roleClaim / roleStateKeyCustomize roles claim lookup

Request view

AccessorContent
this.method / this.path / this.bodyRequest basics
this.headers / this.params / this.queryMaps
this.stateMiddleware bag
this.response(body, status?, headers?)Envelope helper

Errors

Throw or return HTTPException / { status, body } envelopes. See Middleware.

On this page