Skip to main content

HTTP Client

Requires http.enabled: true and URL patterns in http.allowlist in the manifest.

GET request

import { httpGet } from "@luminarys/sdk-as";

const resp = httpGet("https://api.example.com/data");
// resp.status: i32
// resp.headers: HttpHeader[] (name, value)
// resp.cookies: HttpCookie[] (name, value, domain, path, expires, secure, httponly)
// resp.body: Uint8Array
// resp.truncated: bool
const text = String.UTF8.decode(resp.body.buffer);

Parameters:

FieldTypeDefaultDescription
urlstringrequiredRequest URL (must match allowlist)
timeout_msint0 (30s)Request timeout in milliseconds
max_bytesint0 (1 MB)Max response body size. Body is truncated (not rejected) if exceeded

POST request

import { httpPost } from "@luminarys/sdk-as";

const body = Uint8Array.wrap(String.UTF8.encode('{"name": "Alice"}'));
const resp = httpPost("https://api.example.com/users", body, "application/json");
// resp.status, resp.headers, resp.cookies, resp.body, resp.truncated

Custom request

Full control over method, headers, and body.

import { httpRequest, HttpHeader } from "@luminarys/sdk-as";

const hdrs: HttpHeader[] = [];
const h1 = new HttpHeader(); h1.name = "Authorization"; h1.value = "Bearer token123";
const h2 = new HttpHeader(); h2.name = "Content-Type"; h2.value = "application/json";
hdrs.push(h1); hdrs.push(h2);

const body = Uint8Array.wrap(String.UTF8.encode('{"name": "Bob"}'));
const resp = httpRequest("PUT", "https://api.example.com/users/123", body, hdrs);

HttpRequestOptions:

FieldTypeDefaultDescription
methodstring"GET"HTTP method (GET, POST, PUT, DELETE, PATCH, HEAD)
urlstringrequiredRequest URL (must match allowlist)
headersHeader[][]Request headers applied in order
cookiesCookie[][]Request cookies (merged with jar if use_jar is true)
bodybytesemptyRequest body
timeout_msint0 (30s)Request timeout in milliseconds
max_bytesint0 (1 MB)Max response body size. Body is truncated if exceeded
follow_redirectsboolfalseAutomatically follow HTTP 3xx redirects
use_jarboolfalseEnable persistent cookie jar for this skill

Enable use_jar to persist cookies across requests. Cookies are stored per-skill and survive across invocations. Server-sent Max-Age=0 deletes the cookie from the jar.

import { httpRequest, HttpHeader } from "@luminarys/sdk-as";

// Login — cookies saved
const body = Uint8Array.wrap(String.UTF8.encode('{"user":"admin","pass":"secret"}'));
const ct = new HttpHeader(); ct.name = "Content-Type"; ct.value = "application/json";
httpRequest("POST", "https://example.com/login", body, [ct], [], 0, 0, false, true);

// Next request — cookies sent automatically
const resp = httpRequest("GET", "https://example.com/profile",
new Uint8Array(0), [], [], 0, 0, false, true);

Response

HttpResponse:

FieldTypeDescription
statusintHTTP status code
headersHeader[]Response headers (name/value pairs)
cookiesCookie[]Cookies from Set-Cookie headers
bodybytesResponse body (may be truncated)
truncatedbooltrue if body was truncated due to max_bytes limit

Header:

FieldTypeDescription
namestringHeader name
valuestringHeader value

Cookie:

FieldTypeDescription
namestringCookie name
valuestringCookie value
domainstringCookie domain
pathstringCookie path
expiresintExpiry as Unix timestamp (0 = session)
secureboolSecure flag (HTTPS only)
httponlyboolHttpOnly flag (not accessible to JavaScript)

Parsing headers from JSON

All SDKs provide headersFromJSON / HeadersFromJSON / headers_from_json to convert a JSON object string into an ordered Header array. This is useful when headers come from user input or LLM-generated code.

Key property: insertion order from the JSON string is preserved.

import { headersFromJSON, httpRequest } from "@luminarys/sdk-as";

const hdrs = headersFromJSON('{"Authorization":"Bearer tok","Accept":"application/json"}');
const resp = httpRequest("GET", "https://api.example.com/data", new Uint8Array(0), hdrs);

Allowlist patterns

http:
enabled: true
allowlist:
- "https://api.example.com/**"
- "https://*.internal.company.com/**"
- "**" # everything (development only)