Custom HTTP routes
Method-level HTTP routes with httpGet through httpOptions on FusionBaseApi
Convention vs custom
| Mode | How | Mount path |
|---|---|---|
| Convention | Methods named get, post, put, patch, delete, head, options | Class base path from route(...) |
| Custom | httpGet … httpOptions applied to any method | Base 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:
| Helper | HTTP method |
|---|---|
httpGet | GET |
httpPost | POST |
httpPut | PUT |
httpPatch | PATCH |
httpDelete | DELETE |
httpHead | HEAD |
httpOptions | OPTIONS |
Signature: httpGet(route, options?)(handler) — same for the other helpers.
Shared options
Second-argument options object:
| Option | Behavior |
|---|---|
tags | Omit to inherit class route tags; [] clears; […] overrides |
desc | Operation description |
title | Operation summary / title |
deprecated | Mark the operation deprecated |
Path joining and tokens
- Relative templates (no leading
/) join to the classroute(...)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 trailingAction/ACTIONthen 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.