Fusion Framework logo by Cipher UnitFusion

Custom HTTP routes

Method-level HTTP routes with httpGet through httpOptions on FusionBaseApi

Convention vs custom

ModeHowMount path
ConventionMethods named get, post, put, patch, delete, head, optionsClass base path from route(...)
CustomhttpGet … httpOptions applied to any methodBase path joined with the template

Both can live on the same class.

Method helpers

There are no decorators. Apply higher-order helpers to prototype methods, then wrap the class with route(...).

Import from fusion-framework:

HelperHTTP method
httpGetGET
httpPostPOST
httpPutPUT
httpPatchPATCH
httpDeleteDELETE
httpHeadHEAD
httpOptionsOPTIONS

Signature: httpGet(route, options?)(handler) — same for the other helpers.

Shared options

Second-argument options object:

OptionBehavior
tagsOmit to inherit class route tags; [] clears; […] overrides
descOperation description
titleOperation summary / title
deprecatedMark the operation deprecated

Path joining and tokens

  • Relative templates (no leading /) join to the class route(...) base path.
  • Absolute templates starting with / ignore the class base and mount at that path.
  • [module] expands from the class name (UserModule → user).
  • [action] expands from the handler name, stripping a trailing Action / ACTION then lowercasing (UserAction → user).

Example (GET + POST)

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

class UserModule extends FusionBaseApi {
  // Convention: GET /api/user
  get() {
    return this.response({ mode: "convention" }, status.HTTP_SUCCESS);
  }

  UserAction() {
    return this.response({ mode: "custom", action: "user" }, status.HTTP_SUCCESS);
  }

  CreateAction() {
    return this.response({ created: true }, status.HTTP_SUCCESS);
  }

  Purge() {
    return this.response({ purged: true }, status.HTTP_SUCCESS);
  }
}

// Custom: GET /api/user/test/user
httpGet("test/[action]", { title: "User action" })(UserModule.prototype.UserAction);

// Custom: POST /api/user/create/create
httpPost("create/[action]", {
  title: "Create user",
  tags: ["users", "write"],
})(UserModule.prototype.CreateAction);

// Absolute: DELETE /admin/users/purge
httpDelete("/admin/users/purge", { deprecated: true })(UserModule.prototype.Purge);

export const User = route("/api/[module]", { tags: ["users"] })(UserModule);

Registration

Ensure the module file is imported (and route(...) runs) before app.listen().

Sample: examples/custom_http_routes.mjs.

On this page