interface HTTPAPI {
    SendRequest(
        url: string,
        method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH",
        body?: string,
    ): HttpResponse;
}

Methods

Methods

  • Sends a synchronous HTTP request and returns the response.

    When a body is provided, the Content-Type header is automatically set to application/json.

    Parameters

    • url: string

      The full URL to send the request to.

    • method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH"

      HTTP method.

    • Optionalbody: string

      Optional JSON string to send as the request body.

    Returns HttpResponse

    An HttpResponse with the status code and response body.

    A statusCode of 0 indicates a network-level failure (timeout, DNS error, connection refused) — not an HTTP error. Always check statusCode === 0 separately from HTTP 4xx/5xx errors. Request timeout is 30 s; connection timeout is 10 s.

    // GET request
    const res = HTTP.SendRequest("https://api.example.com/data", "GET");
    if (res.statusCode === 0) {
    Console.Error("Network error: " + res.body);
    } else if (res.statusCode === 200) {
    const data = JSON.parse(res.body);
    Console.Log(data.value);
    }

    // POST with JSON body
    const post = HTTP.SendRequest(
    "https://api.example.com/items",
    "POST",
    JSON.stringify({ name: "test" })
    );