Skip to main content
The @api decorator exposes methods of Model or Frame classes as HTTP API endpoints.

Basic Usage

Options

httpMethod

Specifies the HTTP method.
Default: "GET"

path

Specifies the API endpoint path. Default: /{modelName}/{methodName} (camelCase)
Paths are automatically converted to camelCase. UserModel.findById/user/findById

contentType

Specifies the Content-Type of the response. Default: "application/json"
contentType Use Cases:
Notes for application/octet-stream: - Must return Buffer or Uint8Array - Use Content-Disposition header to specify download filename - Use encodeURIComponent() for filenames containing non-ASCII characters - Consider streaming for large files

clients

Specifies the client types to generate. Default: ["axios"]

guards

Specifies API access permissions.

description

Adds API description. Included in generated types and documentation.

resourceName

Specifies the resource name for generated service files.

timeout

Specifies the API request timeout in milliseconds.

cacheControl

Sets the Cache-Control header for the response.
CacheControlConfig Type:
Time notation supports: "10s", "5m", "1h", "1d" formats

compress

Specifies response compression settings.

Complete Options Example

Path Generation Rules

Model Classes

Rules:
  1. Remove “ModelClass” from class name
  2. Convert the rest to camelCase
  3. Format: /{modelName}/{methodName}

Frame Classes

Rules:
  1. Remove “FrameClass” from class name
  2. Convert the rest to camelCase
  3. Format: /{frameName}/{methodName}

Using with Other Decorators

@transactional

Write @api first, then @transactional.

@cache

@upload

@upload is used independently without @api.

Constraints

1. Cannot be combined with other routing decorators (@stream, @websocket, @upload)

@api, @stream, @websocket, and @upload cannot be combined on the same method.
Error Message:

2. Using Multiple Times on Same Method

Using multiple times gives last one priority, and conflicting options cause errors:
Error Message:

3. Only Available in Model/Frame Classes

Generated Code

Using the @api decorator automatically generates:

1. API Route Registration

2. Type Definitions

3. Client Code

Axios:
TanStack Query:

Logging

The @api decorator automatically logs:
Logs are recorded through LogTape, with categories in [model:user] or [frame:auth] format.

Examples

Next Steps

@stream

Create SSE streaming APIs

@transactional

Use database transactions

@upload

Create file upload APIs

@cache

Cache method results