LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page
  • Route Layering
  • Result

Was this helpful?

  1. Cortex API
  2. Decorators
  3. Static

Route

Routes are overridden by name and weight, and sorted by priority (desc), then by weight (desc).

class MyRoute {

  @route('GET c_340_ping', {
    name: 'c_340_get',
    weight: 1
  })
  static get({ req, res, body, next, runtime }) {

    return true

  }

  @route({
    weight: 1,
    method: 'POST',
    name: 'c_340_post',
    path: 'c_340_ping',
    acl: 'role.administrator'
  })
  post({ req, res, body, next, runtime }) {

    return body('myData')

  }

}

@route(options)

Arguments

  • options { Object } Options object

    • name { String }

    • type { String }

    • principal { String }

    • environment { String = "*" }

    • weight { Number = 0 }

    • method { String }

    • path { String }

    • authValidation { Object }

    • urlEncoded { String }

    • plainText { String }

    • apiKey { String }

    • priority { Number }

@route(routeIdentity, options)

Arguments

  • routeIdentity { String } A string defining the route method using the format "<method> <path>"

  • options { Object } Options object

    • name { String }

    • type { String }

    • principal { String }

    • environment { String = "*" }

    • weight { Number = 0 }

    • authValidation { Object }

    • urlEncoded { String }

    • plainText { String }

    • apiKey { String }

    • priority { Number }

Method Options

  • methodOptions { Object } Options passed to the method

    • req { Object }

    • res { Object }

    • body { Object }

    • next { Function }

    • runtime { Object }

      • name { String }

      • type { String }

      • principal { String }

      • environment { String = "*" }

      • weight { Number = 0 }

      • configuration { Object }

        • method { String }

        • path { String }

        • authValidation { Object }

        • urlEncoded { String }

        • plainText { String }

        • apiKey { String }

        • priority { Number }

        • acl { String }

      • metadata { Object }

        • resource { String }

        • className { String }

        • methodName { String }

        • static { Boolean }

        • loc { Object }

          • line { String }

          • column { String }

body(key, value)

Accessor for the script API's body

  • key { string } Key associated to a useful value

  • value { Object | number | string | boolean = undefined } If defined, will create an association between the key and value

Example

const data = body('myData')

next(err)

Calls the API route's next method.

script.api.route.next(err)
  • err { Object = null } Error object

Route Layering

class Ping extends CortexObject {
​
  // run first no api key set, will use that of the caller.
  @log({ traceError: true })
  @route('* *', { priority: 999 })
  static count({ req, res, next, runtime }) {

    try {  
        res.setHeader('Content-Type', 'application/x-ndjson')
    } catch(err) {}

    res.write(JSON.stringify({
        route: `${runtime.configuration.method} /routes/${runtime.configuration.path}`,
        key: req.client.key,
        principal: script.principal.email,
        resource: runtime.metadata.resource
    })+'\n')

    next()    
  }

  // run second, but only if pingCount is 1. pins the app to c_dashboard
  @log({ traceError: true })
  @route('POST pingCount/1', {
    apiKey: 'c_dashboard',
    priority: 2
  })
  static countAgain({ req, res, next, runtime }) {

    try {  
        res.setHeader('Content-Type', 'application/x-ndjson')
    } catch(err) {}

    res.write(JSON.stringify({
        route: `${runtime.configuration.method} /routes/${runtime.configuration.path}`,
        key: req.client.key,
        principal: script.principal.email,
        resource: runtime.metadata.resource
    })+'\n')

    next()    

  }
​
  // run last
  @log({ traceError: true })
  @route('POST pingCount/:num', { priority: 1  })
  static countOnceMore({ req, res, runtime }) {

    try {  
        res.setHeader('Content-Type', 'application/x-ndjson')
    } catch(err) {}

    res.write(JSON.stringify({
        route: `${runtime.configuration.method} /routes/${runtime.configuration.path}`,
        key: req.client.key,
        principal: script.principal.email,
        resource: runtime.metadata.resource
    })+'\n')

  }

}

Result

$> mdctl api POST /routes/pingCount --ndjson
{"route":"* /routes/*","key":"MedableWebAppClientKey","principal":"james@medable.com","resource":"script#type(library).name(c_ping_library).runtime.@route 57:2"}
{"route":"post /routes/pingCount/1","key":"kw30gTF8kXDIiPJYemlDBj","principal":"james@medable.com","resource":"script#type(library).name(c_ping_library).runtime.@route 71:2"}
{"route":"post /routes/pingCount/:num","key":"kw30gTF8kXDIiPJYemlDBj","principal":"james@medable.com","resource":"script#type(library).name(c_ping_library).runtime.@route 86:2"}
$> mdctl tail
{"timestamp":"2020-01-28T23:46:45.398Z","level":"info","message":[{"className":"Ping","methodName":"countAgain","lineNumber":70,"ms":6.93505859375}]}
{"timestamp":"2020-01-28T23:46:45.618Z","level":"info","message":[{"className":"Ping","methodName":"count","lineNumber":56,"ms":6.615966796875}]}
{"timestamp":"2020-01-28T23:46:45.828Z","level":"info","message":[{"className":"Ping","methodName":"countOnceMore","lineNumber":85,"ms":3.302001953125}]}

Last updated 3 years ago

Was this helpful?