curl (function)
Make a web request synchronously using the system libcurl library.
Although most of yavascript is statically-linked, libcurl is not, because it changes often and relies on your system's TLS libraries. To keep its functionality secure and reliable, it's loaded dynamically on demand.
On macOS, we attempt to load "libcurl.dylib". On Windows, we attempt to load "libcurl.dll" or "libcurl-4.dll". On other platforms, we attempt to load "libcurl.so.4" or "libcurl.so".
To make a web request asynchronously, use curl within runInWorker.
@paramurl — The web request url.@paramoptions — Request options. See CurlOptions.@returns- A CurlResponse with the response data.
CurlOptions (type)
Options for curl.
};
CurlOptions.method (string property)
HTTP request method. Defaults to "GET".
Input values get uppercased.
CurlOptions.body (property)
HTTP request body.
CurlOptions.headers (property)
HTTP request headers.
CurlOptions.redirect (property)
Redirect-following behavior. The default value is "follow", meaning redirects will be followed.
CurlResponse (class)
The response object returned by curl.
Although it resembles the standard web Response object, note that its
methods aren't async (and neither is curl).
[name: string]: string[] | undefined;
};
constructor(result: {
response: ArrayBuffer;
responseHeaders: {
[name: string]: string[] | undefined;
};
});
}
CurlResponse.prototype.status (number property)
The status code, eg. 200, 404, etc.
CurlResponse.prototype.headers (object property)
The response headers, with lowercase header names.
The value is an array of strings because headers such as "Set-Cookie" can be specified more than once.
[name: string]: string[] | undefined;
};
CurlResponse.prototype.ok (boolean property)
A boolean indicating whether the status code is >= 200 and <= 299.
CurlResponse.prototype.arrayBuffer (method)
Returns the response body as an ArrayBuffer.
CurlResponse.prototype.bytes (method)
Returns the response body as a Uint8Array.
CurlResponse.prototype.json (method)
Returns the response body as UTF-8 text passed through JSON.parse.
CurlResponse.prototype.text (method)
Returns the response body as UTF-8 text.
CurlResponse (constructor)
constructor(result: {
response: ArrayBuffer;
responseHeaders: {
[name: string]: string[] | undefined;
};
});
CurlResponse.prototype._response (ArrayBuffer property)
The raw response data.