API path to request
path: '/api/kos/ingredients'
path: `/api/devices/${PROP_DEVICE_ID}/status` // with PropKey
Optional methodHTTP method
'get'
Optional lifecycleWhen to execute this request during model lifecycle
If omitted, the request executes when the decorated method is called (method-driven). If specified, the request executes automatically during the given lifecycle phase (lifecycle-driven).
// Lifecycle-driven (auto-execute during LOAD phase)
lifecycle: DependencyLifecycle.LOAD
// Method-driven (execute when method is called)
lifecycle: undefined // or omit entirely
Optional pathPath parameters to expand in the URL Strongly typed from OpenAPI schema Can be static values or PropKey references
// Static value
pathParams: { deviceId: 'device-123' }
// PropKey reference (use PROP_ prefix)
pathParams: { deviceId: PROP_DEVICE_ID }
// Dynamic from method arguments
pathParams: (model, deviceId, status) => ({ deviceId })
Optional queryQuery parameters Strongly typed from OpenAPI schema
// Static
queryParams: { includeMetadata: true, format: 'json' }
// Dynamic from method arguments
queryParams: (model, deviceId, debug) => ({ debug })
Optional bodyRequest body (for POST/PUT/PATCH) Strongly typed from OpenAPI schema
// Static body
body: { action: 'start' }
// Dynamic from method arguments
body: (model, vehicleType, speed) => ({ vehicleType, speed })
Optional iterateJSON path to iterate over in response Creates models for each item in the array
iterateOver: 'data.ingredients' // Iterates response.data.ingredients array
Optional modelModel registration object for creating instances from array items Used with iterateOver to create child models using the builder pattern
modelFactory: IngredientModel // The registration object itself
deprecated The old curried function signature is deprecated:
modelFactory?: (id: string) => (options: any) => IKosDataModel
Optional idFunction to extract the model ID from response data items Required when using modelFactory if items don't have an 'id' field
idExtractor: (item) => item.ingredientId
idExtractor: (item) => `${item.type}-${item.index}`
Optional mappingsField mappings for data transformation Same format as
mappings
mappings: [
{ from: 'id', to: 'id' },
{ from: 'ingredientId', to: 'ingredientId' },
{ from: 'metadata.calories', to: 'calories', transform: 'number' }
]
Optional extensionsExtension points to execute during transformation
extensions: [
{ type: 'data-mapper', extension: ExtensionType.IngredientMapper }
]
Optional transformTransformation function for response data Applied before mappings
transform: (response) => response.data
Optional conditionCondition to determine if request should execute
condition: (model) => model.isInitialized
Optional errorError handling strategy
errorHandler: {
strategy: 'default',
defaultValue: [],
onError: (error, model) => model.logger.error('Failed to load', error)
}
Optional cacheResponse caching configuration Controls how long responses are stored and when they're cleaned up
{ retention: ResponseRetention.SINGLE }
// No caching - clear immediately after handler
cache: { retention: ResponseRetention.IMMEDIATE }
// Cache for 5 minutes
cache: { retention: ResponseRetention.TTL, ttl: 5 * 60 * 1000 }
// Keep for model lifetime
cache: { retention: ResponseRetention.PERMANENT }
Optional requestRequest options for controlling fetch behavior These are merged with runtime options passed to ctx.$request() Runtime options take precedence over decorator options
Rest ...args: any[]// Set default timeout and destination for all requests
requestOptions: {
destinationAddress: 'device-123',
timeout: 10000
}
// Dynamic from method arguments
requestOptions: (model, ...args) => ({
destinationAddress: model.deviceId,
headers: { 'X-Session': model.sessionId }
})
Configuration parameters for
Kos Service Request
decorator Enables lifecycle-driven HTTP requests with declarative data transformation
Typeparam
Paths - The OpenAPI paths type (from your OpenAPI schema)
Typeparam
Path - The specific API path being requested
Typeparam
Method - The HTTP method type
Typeparam
Response - The raw response type from the API
Typeparam
TransformedResponse - The transformed response type after mappings