ExisJS

Decorators (exisjs/decorators)

ExisJS provides a robust Object-Oriented Programming (OOP) paradigm via the exisjs/decorators module.

Unlike frameworks that depend on heavy reflection libraries, ExisJS decorators are built completely on standard ECMAScript decorators and do not require reflect-metadata.


1. Controller & Routing

@Controller(prefixOrOptions?)

Marks a class as a Controller. All route handler methods within the class will be grouped under the specified prefix.

src/http/users/route.ts
import { Controller } from 'exisjs/decorators'
@Controller('/users')export default class UserController {  // ...}

HTTP Methods

Defines an HTTP route handler on a class method. You can optionally pass a schema to validate incoming requests.

  • @Get(path?, schema?)
  • @Post(path?, schema?)
  • @Put(path?, schema?)
  • @Patch(path?, schema?)
  • @Delete(path?, schema?)
  • @Options(path?, schema?)
  • @Head(path?, schema?)
  • @Connect(path?, schema?)
  • @Trace(path?, schema?)
  • @All(path?, schema?)
src/http/users/route.ts
import { Controller, Get, Post } from 'exisjs/decorators'import { tex } from 'exisjs/validator'
@Controller('/users')export default class UserController {  @Get('/:id')  getUser() {    return { id: 1 }  }
  @Post('/', { body: tex.object({ name: tex.string() }) })  createUser() {    return { success: true }  }}

2. Parameter Injection

Parameter decorators automatically extract data from the incoming request and inject them directly into your method arguments:

  • @Body(nameOrPipe?): Parses and injects the JSON request body (or passes it through a validator/pipe).
  • @Param(nameOrPipe?): Injects a URL path parameter (e.g., id from /:id).
  • @Headers(nameOrPipe?): Injects an HTTP header by name.
  • @HostParam(nameOrPipe?): Injects a subdomain parameter.
  • @Req(): Injects the raw ExisJS Request object.
  • @Res(options?): Injects the raw ExisJS Response object ({ passthrough: true }).
  • @Ip(): Injects the client's IP address.
  • @Next(): Injects the Next function.

3. Middleware & Pipeline Decorators

  • @Use(...middlewares): Binds standard Express-style or ExisJS middleware to a controller class or method.
  • @Idempotent(options?): Caches responses based on the Idempotency-Key header using native in-memory off-heap storage.

4. Response & Metadata Modifiers

  • @HttpCode(code: number): Enforces a custom HTTP status code on success.
  • @Header(name: string, value: string): Appends an HTTP header to the response.
  • @Returns(schema): Attaches response schema for OpenAPI documentation.
  • @Redirect(url: string, statusCode?: number): Redirects request to target URL.
  • @Permissions(...permissions: string[]): Sets required permissions on the route.
  • @Hosts(...hosts: string[]): Restricts routes to specific Host headers.

5. Dependency Injection

  • @Injectable(options?): Marks a service class as an IoC provider managed by the container.
  • @Boundary(config): Marks a class as a folder-scoped Boundary configuring CORS, headers, exclusions, and pipeline steps.
  • @Server(config): Marks a class as a root server definition.