httpFetch(url, [options])
Calls a URL and returns the full HTTP response — status code, response headers and the raw, unparsed body — unlike httpGet, which returns only the JSON-parsed body. Use it to inspect any web page or API: security headers, HTTP→HTTPS redirects, raw HTML, compression and timing. gzip/deflate/br bodies are decompressed automatically while the original content-encoding header is kept. On failure it returns { DoclyError: "..." } instead of throwing. It can also send files: multipart/form-data with text and file parts (multipart), or the raw bytes of one file as the body (bodyBase64).
Parameters
urlstringrequiredURL to call.
optionsobjectoptionaloptionsobjectRequest options (see the Options table below). All fields optional. Fields: method (string, default "GET") HTTP method (GET, HEAD, POST, PUT, DELETE, ...); headers (object) name/value object converted to HTTP request headers, a Content-Type header (any casing) is moved to the request body instead (contentType wins if both are set, and it is dropped when no body is sent); body (string | object) request body, objects are serialized to JSON; bodyBase64 (string) the request body as base64 of raw bytes, sent unchanged, for APIs that take a file directly in the body (Content-Type is contentType as given, otherwise application/octet-stream, and no charset is added); multipart (array) sends multipart/form-data with text parts { name, value } and file parts { name, fileName, contentType, base64 } in the given order: Docly creates the boundary and the Content-Type, a string value is sent as is, numbers as JavaScript writes them, an object or array as JSON (application/json; charset=utf-8), a file part without contentType is application/octet-stream, and file names are sent as UTF-8 like a browser does; use only one of body, bodyBase64 and multipart; contentType (string, default "application/json") Content-Type used when a body is sent, parameters such as "application/json; charset=utf-8" are accepted and charset=utf-8 is added when none is given, with multipart only "multipart/form-data" is accepted and Docly adds its own boundary; followRedirects (bool, default true) follow 3xx redirects, set false to inspect the location header yourself (e.g. detect HTTP→HTTPS); timeoutMs (number, default 10000) request timeout in milliseconds, clamped to 1000–60000; maxBodyBytes (number, default 2000000) max body bytes returned, clamped to 1024 and the limit per call (30 MB unless Docly support has raised it for your subscription), larger bodies are cut and truncated is set; responseType (string, default "text") "text" returns body as UTF-8 text, "base64" returns body as base64 of the raw bytes for binary files such as PDFs and images (any other value gives text), always check truncated for binary files since a cut file is unusable; blockPrivateNetworks (bool, default false) when true, blocks requests whose host resolves to a loopback / private / link-local address (SSRF guard), checked for every connection including each redirect hop.
Returns
Returns an object with the full response:
| Field | Description |
|---|---|
ok | true for 2xx status codes |
status | HTTP status code |
statusText | HTTP status text |
url | Final URL (after redirects) |
redirected | true if at least one redirect was followed |
timeMs | Request duration in milliseconds |
headers | Response headers (keys lower-cased) |
contentType | Response Content-Type |
contentEncoding | Original content-encoding header |
contentLength | Bytes received, before decompression |
truncated | true if the body was cut to maxBodyBytes |
limitMessage | Set when the body was cut by the limit per call, not by your own maxBodyBytes: says the limit and that Docly support can raise it. Otherwise null |
body | Raw, unparsed response body: UTF-8 text, or base64 of the bytes with responseType: "base64" |
On error: { DoclyError }.
Limit per call: the body one call sends and the body it returns may each be up to 30 MB. Docly support can raise the limit for a subscription. A request body over the limit is not sent: the call returns { DoclyError } with the size, the limit and how to get it raised. A response over the limit is cut, truncated is true and limitMessage says why.
Security: requests to Docly's own platform domains (and their subdomains) and to cloud metadata / link-local addresses are always blocked — also after a redirect — and the call returns { DoclyError }. The Host header cannot be set. Private networks are only blocked by httpFetch with blockPrivateNetworks: true.
Example
// Fetch a page with the full response (raw HTML + headers)
var r = docly.httpFetch("https://somewebsite.com", {
followRedirects: true,
timeoutMs: 10000
});
// Handle error
if (r.DoclyError) throw new Error(r.DoclyError);
// Inspect security headers (keys are lower-cased)
var hasHsts = !!r.headers["strict-transport-security"];
var hasCsp = !!r.headers["content-security-policy"];
// Inspect the raw HTML body
var isWordPress = r.body.indexOf("wp-content") >= 0;
return JSON.stringify({
status: r.status,
timeMs: r.timeMs,
hsts: hasHsts,
csp: hasCsp,
wordpress: isWordPress
});
// Download a binary file (e.g. a PDF) as base64
var pdf = docly.httpFetch("https://somewebsite.com/price-list.pdf", {
responseType: "base64",
maxBodyBytes: 10000000
});
if (pdf.DoclyError) throw new Error(pdf.DoclyError);
if (pdf.truncated) throw new Error("File is larger than maxBodyBytes");
var pdfBase64 = pdf.body; // base64 of the exact bytes
// Content-Type may also be given as a header
var e = docly.httpFetch("https://api.example.com/v1/embeddings", {
method: "POST",
headers: { "Content-Type": "application/json", "Authorization": "Bearer ..." },
body: { input: "text" }
});
// Upload files with multipart/form-data: a JSON part, an image and a PDF
var image = docly.getEmbeddedFile("Products/1234567.json", "image.jpg");
var sheet = docly.getEmbeddedFile("Products/1234567.json", "datasheet.pdf");
var up = docly.httpFetch("https://api.example.com/products/upload", {
method: "POST",
headers: { "Authorization": "Bearer ..." },
multipart: [
{ name: "product", value: { id: 1234567, name: "Lamp" } },
{ name: "image", fileName: "1234567.jpg", contentType: "image/jpeg", base64: base64(image) },
{ name: "datasheet", fileName: "1234567.pdf", contentType: "application/pdf", base64: base64(sheet) }
]
});
if (up.DoclyError) throw new Error(up.DoclyError); // e.g. over the limit per call
// Send one file as the raw request body
var put = docly.httpFetch("https://api.example.com/files/1234567.pdf", {
method: "PUT",
contentType: "application/pdf",
bodyBase64: base64(sheet)
});