ctx
) is a crucial component in Blok that facilitates data sharing and state management across different Nodes within a single Workflow execution instance. It acts as a shared memory space, allowing Nodes to pass information to subsequent Nodes, access initial trigger data, and maintain state throughout the lifecycle of a workflow run.
Blok
, the Context Object (ctx
) has a specific structure that enables nodes to exchange data and maintain state throughout execution:
ctx.request
: Contains all HTTP request details:
body
: The request payload (e.g., for POST, PUT requests)method
: HTTP method (e.g., GET, POST, etc.)headers
: Request headersquery
: Query parameters (e.g., ?key=value
)params
: Path parameters (e.g., /:id
)ctx.response
: Holds workflow outputs:
data
: The latest processed data from nodesctx.vars
: Temporary workflow variables:
input
which is often populated from the context by the workflow engine), perform their operations, and then write their results back to the context if those results need to be accessed by subsequent nodes.
ctx.request.params
id
from the request URL and fetch details from MongoDB:
path: "/movies/:id"
defines a dynamic route.id
from the URL (e.g., /movies/123
→ ctx.request.params.id = 123
).ctx.vars
fetch-data
) fetches API data and stores it in ctx.vars['fetch-data']
.process-data
) extracts and processes values from ctx.vars['fetch-data']
.nodeName.outputKey
, shared.config.apiKey
).inputSchema
.ctx
allows passing request data to nodes.ctx.vars
.ctx.response.data
.ctx.request.params
, ctx.request.body
, and ctx.response
drive workflow execution.