Chain

A chain is a intermediate data type to enable complex template values. Chains also provide additional customization, such as marking values as sensitive.

To use a chain in a template, reference it as {{chains.<id>}}.

Fields

FieldTypeDescriptionDefault
sourceChainSourceSource of the chained valueRequired
sensitivebooleanShould the value be hidden in the UI?false
selectorJSONPathSelector to transform/narrow down results in a chained value. See Filtering & Queryingnull
selector_modeSelectorModeControl selector behavior when query returns multiple resultsauto
content_typestringForce content type. Not required for request and file chains, as long as the Content-Type header/file extension matches the data. See here for a list of supported types.
trimChainOutputTrimTrim whitespace from the rendered outputnone

See the ChainSource docs for detail on the different types of chainable values.

Chain Output Trim

This defines how leading/trailing whitespace should be trimmed from the resolved output of a chain.

VariantDescription
noneDo not modify the resolved string
startTrim from just the start of the string
endTrim from just the end of the string
bothTrim from the start and end of the string

Selector Mode

The selector mode controls how Slumber handles returns JSONPath query results from the selector field, relative to how many matches the query returned. The table below shows how each mode behaves for a query that produces no values ($.id) a single value ($[0].name) vs multiple values ($[*].name) for this example data:

[{ "name": "Apple" }, { "name": "Kiwi" }, { "name": "Mango" }]
VariantDescription$.id$[0].name$[*].name
autoIf query returns a single value, use it. If it returns multiple, use a JSON arrayErrorApple["Apple", "Kiwi", "Mango"]
singleIf a query returns a single value, use it. Otherwise, error.ErrorAppleError
arrayReturn results as an array, regardless of count.[]["Apple"]["Apple", "Kiwi", "Mango"]

The default selector mode is auto.

Examples

# Load chained value from a file
username:
  source: !file
    path: ./username.txt
---
# Prompt the user for a value whenever the request is made
password:
  source: !prompt
    message: Enter Password
  sensitive: true
---
# Prompt the user to select a value from a static list
fruit:
  source: !select
    message: Select Fruit
    options:
      - apple
      - banana
      - guava
---
# Use a value from another response
# Assume the request recipe with ID `login` returns a body like `{"token": "foo"}`
auth_token:
  source: !request
    recipe: login
  selector: $.token
---
# Use the output of an external command
username:
  source: !command
    command: [whoami]
    trim: both # Shell commands often include an unwanted trailing newline