JetBrains response handler syntax
Section titled “JetBrains response handler syntax”JetBrains introduced inline JavaScript response handlers placed after the request body using > followed by a script block. External script files can also be referenced: > ./handler.js
GET https://api.example.com/users
> {%
client.test("Status is 200", function() {
client.assert(response.status === 200);
});
client.global.set("count", response.body.length);
%}
GET https://api.example.com/users
> {%
client.test("Status is 200", function() {
client.assert(response.status === 200);
});
%}
GET https://api.example.com/users
{{
const { equal } = require('assert');
test('status is 200', () => {
equal(response.statusCode, 200);
});
}}
GET https://api.example.com/users
?? status == 200
?? header content-type includes json
?? duration < 500
JavaScript API
Section titled “JavaScript API”client object: client.test(name, fn), client.assert(condition, msg), client.log(text), client.global.set/get/clear/clearAll(), client.global.headers.set(name, value), client.exit().
response object: response.body (parsed JSON, XML DOM, or string), response.status, response.headers.valueOf(name), response.headers.valuesOf(name), response.contentType.mimeType, response.contentType.charset, response.cookiesByName(name).
Scripts use ECMAScript 2023.
httpyac script blocks
Section titled “httpyac script blocks”httpyac uses double-brace blocks positioned after the request. Scripts have access to response (with .statusCode, .headers, .body, .parsedBody, .timings), full Node.js require(), and built-in test() and sleep() functions.
httpyac also supports the JetBrains response handler syntax for compatibility.
Built-in test helpers
Section titled “Built-in test helpers”httpyac provides convenience methods for common assertions:
test.status(code)— verify HTTP status codetest.totalTime(ms)— check request durationtest.header(name, value)— assert header valuetest.headerContains(name, value)— assert header contains substringtest.responseBody(content)— assert exact body matchtest.hasResponseBody()/test.hasNoResponseBody()— check body presence
Event-specific script hooks
Section titled “Event-specific script hooks”httpyac provides event-specific hooks: @request (runs after variable replacement, before sending), @streaming (runs during streaming connections), @response (runs on response receipt), @responseLogging (runs on response output), and @after (runs after all requests complete).
Global script registration
Section titled “Global script registration”Scripts can be registered to execute across all requests in a file using the + prefix. For example, a block with +after runs after every request. A block with just + runs before every request.
httpyac assertion syntax
Section titled “httpyac assertion syntax”A compact assertion syntax unique to httpyac:
GET https://api.example.com/users
?? status == 200?? header content-type includes json?? duration < 500?? body $.users[0].name == John?? js response.parsedBody.total > 0Supported assertion types: status, header, body, duration, js, xpath.
Operators: ==, !=, >, >=, <, <=, startsWith, endsWith, includes/contains, exists, matches, sha256, sha512, md5.
kulala.nvim
Section titled “kulala.nvim”Supports both JetBrains-style response handler scripts and Lua scripting. Also provides built-in assert functions.
VS Code REST Client and Visual Studio 2022
Section titled “VS Code REST Client and Visual Studio 2022”Neither supports response handler scripts or assertions. Response data is accessed only through named request variables.
| Feature | VS Code | JetBrains | httpyac | VS 2022 | kulala |
|---|---|---|---|---|---|
| Response handler scripts (> {% %}) httpyac supports for JetBrains compatibility. | |||||
| Response handler scripts ({{ }}) httpyac-native syntax with full Node.js require() access. | |||||
| Pre-request scripts (< {% %}) | |||||
| Pre-request scripts ({{ }} before request) | |||||
| Assertion syntax (?? status == 200) Supports status, header, body, duration, js, xpath assertions. | |||||
| client.test() API | |||||
| Crypto API in scripts crypto.hmac.sha256(), crypto.sha256(), etc. | |||||
| Lua scripting > {% --lua ... %}. Unique to kulala.nvim. | |||||
| External response handler file (> filepath.js) | |||||
| Event-specific script hooks {{@request}}, {{@streaming}}, {{@response}}, {{@responseLogging}}, {{@after}}. | |||||
| Global script registration ({{+...}}) Registers scripts to execute across all requests. {{+after}} runs after every request. | |||||
| Built-in test helpers (test.status(), test.header()) test.status(), test.totalTime(), test.header(), test.headerContains(), test.responseBody(), etc. |