@api decorator exposes methods of Model or Frame classes as HTTP API endpoints.
Basic Usage
Options
httpMethod
Specifies the HTTP method."GET"
path
Specifies the API endpoint path. Default:/{modelName}/{methodName} (camelCase)
Paths are automatically converted to camelCase.
UserModel.findById → /user/findByIdcontentType
Specifies the Content-Type of the response. Default:"application/json"
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 filesclients
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.compress
Specifies response compression settings.Complete Options Example
Path Generation Rules
Model Classes
- Remove “ModelClass” from class name
- Convert the rest to camelCase
- Format:
/{modelName}/{methodName}
Frame Classes
- Remove “FrameClass” from class name
- Convert the rest to camelCase
- Format:
/{frameName}/{methodName}
Using with Other Decorators
@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.
2. Using Multiple Times on Same Method
Using multiple times gives last one priority, and conflicting options cause errors: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:Logging
The@api decorator automatically logs:
[model:user] or [frame:auth] format.
Examples
- Basic CRUD
- Caching
- Access Control
- Custom Paths
Next Steps
@stream
Create SSE streaming APIs
@transactional
Use database transactions
@upload
Create file upload APIs
@cache
Cache method results