Skip to main content

rm.* API Reference

The rm.* namespace is Rostyman's scripting API, available in both pre-request and test scripts.

rm.environment

Read and write variables in the active environment for the current request's collection.

rm.environment.get('key')           // → string | undefined
rm.environment.set('key', 'value') // → void
rm.environment.unset('key') // → void
rm.environment.clear() // removes all env vars
rm.environment.has('key') // → boolean

rm.collectionVariables

Read and write collection variables.

rm.collectionVariables.get('key')
rm.collectionVariables.set('key', 'value')
rm.collectionVariables.unset('key')
rm.collectionVariables.has('key')

rm.globals

Read and write global variables (shared across all collections).

rm.globals.get('key')
rm.globals.set('key', 'value')
rm.globals.unset('key')
rm.globals.has('key')

rm.variables

Read and write request-scoped variables by priority order (local → environment → collection → globals). Variables set here are available for the current request only (including auth resolution) and are not persisted to the database.

rm.variables.get('key')           // resolves by priority
rm.variables.set('key', 'value') // set a request-scoped variable
rm.variables.has('key') // → boolean

Common use case — set a token in pre-request script for auth:

const token = rm.environment.get("platformUserToken") || rm.environment.get("platformToken");
rm.variables.set("activeToken", token);
// {{activeToken}} is now available in Bearer auth and other fields

rm.response

Available in test scripts only (after the response is received).

rm.response.code           // number — HTTP status code (e.g., 200)
rm.response.status // string — status text (e.g., "OK")
rm.response.responseTime // number — time in milliseconds
rm.response.headers // object — response headers (lowercase keys)
rm.response.json() // object — parsed JSON body
rm.response.text() // string — raw body text

Examples

rm.response.code                          // 200
rm.response.status // "OK"
rm.response.responseTime // 142
rm.response.headers['content-type'] // "application/json"
rm.response.json().id // 42
rm.response.text() // '{"id":42,"name":"Alice"}'

rm.test

Define a test case.

rm.test('description', () => {
// throw or call rm.expect() to fail
})

rm.expect

Chai BDD assertion. Throws if the assertion fails, which marks the test as failed.

rm.expect(value)
.to.equal(expected)
.to.include(substring)
.to.have.property('key')
.to.be.a('string' | 'number' | 'boolean' | 'array' | 'object')
.to.be.an('array')
.to.be.ok // truthy
.to.be.null
.to.be.undefined
.to.be.above(n)
.to.be.below(n)
.to.be.within(min, max)
.to.have.lengthOf(n)
.not.to.equal(x) // negate any assertion with .not

Limitations

  • No require() — the sandbox does not have access to Node.js modules
  • No network calls — use pre-request scripts with rm.sendRequest for that (future)
  • 5-second timeout — scripts that run longer are killed
  • No access to the DOM or browser APIs