JavaScript Scripting API Overview
January 18, 2026 · View on GitHub
LazyCurl provides a powerful JavaScript scripting API for automating request workflows, testing responses, and managing data dynamically.
Runtime: Goja JavaScript engine (ES5.1+)
For the complete single-page reference, see Scripting API Reference.
Table of Contents
Script Types
| Type | Execution | Use Case |
|---|---|---|
| Pre-request | Before HTTP request is sent | Add auth headers, modify URL, generate dynamic data |
| Post-response | After HTTP response received | Validate response, extract data, run tests |
Quick Reference
Core Modules
| Module | Description | Docs |
|---|---|---|
lc.request | HTTP request manipulation (URL, headers, body, params) | 14 methods/properties |
lc.response | HTTP response access (status, headers, body) | 7 methods/properties |
lc.env | Environment variables (persisted to file) | 5 methods |
lc.globals | Session variables (in-memory) | 6 methods |
lc.test | Test definitions and assertions | 16 matchers |
Utility Modules
| Module | Description | Docs |
|---|---|---|
lc.cookies | Cookie management | 7 methods |
lc.crypto | Hash functions and HMAC | 7 methods |
lc.base64 | Base64 encoding/decoding | 4 methods |
lc.variables | Dynamic data generation | 12 methods |
lc.info | Execution context info | 6 properties |
lc.sendRequest | Request chaining | 1 method |
console | Logging | 5 methods |
The lc Global Object
All scripting APIs are accessible through the lc global object:
// Pre-request: Add authentication header
var token = lc.env.get("auth_token");
if (token) {
lc.request.headers.set("Authorization", "Bearer " + token);
}
// Post-response: Validate and store data
lc.test("Status is 200", function() {
lc.expect(lc.response.status).toBe(200);
});
var data = lc.response.body.json();
if (data && data.token) {
lc.env.set("auth_token", data.token);
}
Getting Started
1. Add a Pre-request Script
Navigate to the Pre-request tab in the Request panel and add:
// Add timestamp header
lc.request.headers.set("X-Request-Time", Date.now().toString());
// Add API key from environment
var apiKey = lc.env.get("api_key");
if (apiKey) {
lc.request.headers.set("X-API-Key", apiKey);
}
2. Add a Post-response Script
Navigate to the Post-response tab and add:
// Log response info
console.log("Status: " + lc.response.status);
console.log("Time: " + lc.response.time + "ms");
// Run tests
lc.test("Response is successful", function() {
lc.expect(lc.response.status).toBe(200);
});
lc.test("Response has data", function() {
var data = lc.response.body.json();
lc.expect(data).not.toBeNull();
});
3. Send the Request
Press Ctrl+S to send. View results in:
- Console tab: Script logs
- Tests tab: Assertion results
API Modules
Request & Response
-
lc.request - Read and modify the HTTP request
lc.request.method- HTTP method (read-only)lc.request.url- Request URLlc.request.headers.*- Header manipulationlc.request.body.*- Body access/modificationlc.request.params.*- Query parameter access
-
lc.response - Access HTTP response data
lc.response.status- HTTP status codelc.response.headers.*- Response headerslc.response.body.*- Response body
Variables
- lc.env - Environment variables persisted to disk
- lc.globals - Session variables in memory
Testing
Utilities
- lc.cookies - Cookie management
- lc.crypto - Cryptographic hash functions
- lc.base64 - Base64 encoding/decoding
- lc.variables - Generate random test data
- lc.info - Script execution context
- lc.sendRequest - Chain multiple requests
- console - Logging functions