Webtask

Documentation

The Webtask Context

Using the context object in your tasks

For customized documentation and ready to run samples, please log in.

What is the Context Object

In Webtask, there is a context object available with quite a few useful properties that can be accessed while running your tasks.

var context = {
  meta,
  storage,
  data: {},
  params: {},
  query: {},
  secrets: {},
  headers: req.headers
};

Meta

Themeta property is an object containing the metadata properties of the task being executed, or an empty object if there are none.

Storage

The storage property is an instance of the storage interface . The context.storage.get and the context.storage.set methods can be used to access or store items. See the storage interface documentation for more details.

Data

The data property is a catch-all object that is the equivalent to:

claims.mb ? Object.assign(
  {}, 
  req.query, 
  context.params, 
  context.secrets, 
  context.body
) : Object.assign(
  {}, 
  req.query, 
  context.params, 
  context.secrets
)

In other words, it will contain the overlay of query params, Webtask token params (pctx), Webtask secrets, and the body (when the mb claim is 1).

However, it is not recommended to rely on the data property to obtain these values. Instead, they should be accessed directly from their own properties, such as context.secrets, context.query, or context.body.

Params

The params parameter is deprecated. It is similar to an unencrypted secrets parameter, and should no longer be used.

Query

The query parameter is the parsed query-string. It is parsed using querystring, so it does not support the dot syntax that things like qs support.

Secrets

The secrets parameter is an object containing Webtask secrets (or an empty object, if there are none). Secrets provide a place to securely store private information, such as tokens or IDs. For more information about secrets, take a look at the secrets documentation.

Headers

The headers parameter contains the unmodified headers from the request received by the Webtask sandbox.