Skip to the content.

Request Chaining

Request chaining takes a value from one response and uses it in later requests, for example a token from a login call, the ID of a newly created resource, or a session ID. It works only in HTTP mode with weighted endpoints.

target: https://api.example.com
concurrency: 10
duration: 1m
endpoints:
  - name: login
    weight: 1
    method: POST
    path: /auth/login
    headers: { Content-Type: application/json }
    body: '{"email":"perf@example.com","password":"secret"}'
    extractors:
      - { jsonpath: $.token, var: auth_token }
      - { jsonpath: $.user.id, var: user_id }

  - name: profile
    weight: 5
    path: /users/{{user_id|me}}
    headers:
      Authorization: "Bearer {{auth_token|}}"

Placeholders

When a request is built, each placeholder is looked up in this order:

  1. Variables extracted earlier by this worker
  2. Fields of the current feeder record (see Data Feeders)
  3. The default after |

Values are inserted as-is, with no URL or JSON escaping.

Placeholders work in URLs, endpoint paths, header values and bodies. Names are matched exactly; spaces inside the braces are not trimmed. Go-template syntax such as {{.field}} is not supported in requests.

Extractors

You attach extractors to an endpoint. Each extractor needs exactly one of jsonpath or regex, plus a var name. The name must be a valid identifier: letters, digits and underscores, and it cannot start with a digit.

Key Description
jsonpath A path in gjson syntax. A leading $. is stripped, and $ on its own means the whole document.
regex Go regular expression. The first capture group is extracted, or the whole match when the pattern has no groups.
var Variable to store the value in.
on_error Also run this extractor when the response status is >= 400. Default false.
extractors:
  - jsonpath: id                 # top-level field
    var: order_id
  - jsonpath: $.items.0.sku      # array index
    var: first_sku
  - jsonpath: $                  # whole body
    var: raw
  - regex: 'session=([a-f0-9]+)'
    var: session_id
  - jsonpath: error.code
    var: last_error
    on_error: true

When extractors run:

Note: If an extractor finds nothing (path missing or regex no match), Crankfire prints a warning to stderr and stores an empty string. That empty value counts as “set”, so later lookups return "" and ignore any |default. Defaults apply only while a variable has never been set in that worker.

Scope: one store per worker

Each worker goroutine (concurrency of them) has its own variable store, which lasts for the whole run.

Ordering: endpoints are picked at random

Endpoints are chosen at random by weight for each request. There is no “step 1, then step 2”. A worker’s first request might be profile before it has ever run login. Design for that:

Limits