Request variables

When a request is named with ### REQUEST_NAME, later requests can reference its request or response data.

Syntax

text
{{REQUEST_NAME.(response|request).(body|headers).(JSONPath|header name)}}
  • Body: use JSONPath after body. - e.g. $.id, $.body.token
  • Headers: {{REQUEST_NAME.response.headers.Date}} or {{REQUEST_NAME.response.headers['Date']}}
  • Cookies: {{REQUEST_NAME.response.cookies.CookieName.value}}

Run the source request first so its response is available. Kulala persists the latest response per named request in the document store.

VS Code REST Client chaining

If you migrated from the VS Code REST Client extension, enable the compat flag at the top of the file:

vscode-restclient-compat.httphttp
# @kulala-vscode-restclient-compat

### REQUEST_ONE

POST https://echo.kulala.app/post HTTP/1.1
Accept: application/json
Content-Type: application/json

{
  "token": "foobar"
}

### REQUEST_TWO
POST https://echo.kulala.app/post HTTP/1.1
Accept: application/json
Content-Type: application/json

{
  "token": "{{REQUEST_ONE.response.body.$.body.token}}"
}

###

POST https://echo.kulala.app/post HTTP/1.1
Accept: application/json
Content-Type: application/json

{
  "date_header": "{{REQUEST_TWO.response.headers['Date']}}"
}

Without # @kulala-vscode-restclient-compat, {{REQUEST_ONE.response…}} references resolve to empty strings. The flag propagates through import and run from the source file.

See Migration for more detail.

Token persistence example

A common pattern: fetch a token, save it to disk, reuse on the next run:

token-persistence.httphttp
### NAMED_REQUEST_INSECURE

< {%
var fs = require('fs');
if (!fs.existsSync('TOKEN.txt')) {
  console.log('TOKEN.txt not found, requiring new token');
} else {
  console.log('TOKEN.txt found, using token from file');
}
%}

// @kulala-curl--insecure
POST https://echo.kulala.app/post HTTP/1.1
Content-Type: application/json
X-Custom-Header: Kulala-Insecure

{
  "token": "some-insecure-token"
}

> ./simple.post.http.js

> {%
  const fs = require('fs');
  fs.writeFileSync('TOKEN.txt', response.body.body.token);
%}