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

TypeExecutionUse Case
Pre-requestBefore HTTP request is sentAdd auth headers, modify URL, generate dynamic data
Post-responseAfter HTTP response receivedValidate response, extract data, run tests

Quick Reference

Core Modules

ModuleDescriptionDocs
lc.requestHTTP request manipulation (URL, headers, body, params)14 methods/properties
lc.responseHTTP response access (status, headers, body)7 methods/properties
lc.envEnvironment variables (persisted to file)5 methods
lc.globalsSession variables (in-memory)6 methods
lc.testTest definitions and assertions16 matchers

Utility Modules

ModuleDescriptionDocs
lc.cookiesCookie management7 methods
lc.cryptoHash functions and HMAC7 methods
lc.base64Base64 encoding/decoding4 methods
lc.variablesDynamic data generation12 methods
lc.infoExecution context info6 properties
lc.sendRequestRequest chaining1 method
consoleLogging5 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 URL
    • lc.request.headers.* - Header manipulation
    • lc.request.body.* - Body access/modification
    • lc.request.params.* - Query parameter access
  • lc.response - Access HTTP response data

    • lc.response.status - HTTP status code
    • lc.response.headers.* - Response headers
    • lc.response.body.* - Response body

Variables

  • lc.env - Environment variables persisted to disk
  • lc.globals - Session variables in memory

Testing

Utilities


See Also


← Back to Documentation | lc.request →