Nimbu Developer Docs
Module Reference

http

Outbound HTTP client for Cloud Code, with SSRF protection, a fixed deadline and a response size cap.

What This Adds In Cloud Code

  • Outbound HTTP client for Cloud Code integrations.
  • Every request goes through a pinned, SSRF-hardened connection (see Limits And Network Policy).
  • Same response shape for all verbs.

Quick Start

const HTTP = require('http');
const result = HTTP.get('https://api.example.com/v1/status');

API

FunctionParamsReturnsNotes
get(url, options)URL + optional request optionsHttpResponseNo body payload.
head(url, options)URL + optional request optionsHttpResponseHeaders only from upstream.
delete(url, options)URL + optional request optionsHttpResponseNo body payload.
post(url, payload, options)URL + body + request optionsHttpResponseSee payload rules below.
put(url, payload, options)URL + body + request optionsHttpResponseSame as post.
patch(url, payload, options)URL + body + request optionsHttpResponseSame as post.

The calls are synchronous. await works on them but is not needed.

HttpResponse shape:

{ code: 200, headers: { content_type: 'application/json', ... }, body: '...', cookies: { ... } }
  • 4xx and 5xx responses are returned, not thrown. Check code yourself. The body is read for error responses too.
  • Header names are lowercase with - replaced by _ (headers.content_type). headers.set_cookie is an array; other repeated headers are joined with , .

options behavior:

  • All non-reserved keys are sent as request headers (for example Authorization, 'Content-Type'). Pass them directly, not nested under a headers key.
  • base64: true base64-encodes the response body (use it for binary downloads).
  • skipUrlNormalization: true sends the URL as given instead of normalizing its encoding.
  • params: { ... } is appended to the URL as a query string.
  • cookies: { name: 'value' } is sent as a Cookie header.

payload rules:

  • A string is sent as-is. To send JSON, pass JSON.stringify(data) and set 'Content-Type': 'application/json'.
  • An object is sent form-encoded (application/x-www-form-urlencoded), which overrides any Content-Type you set.

Practical Example

const HTTP = require('http');

const syncResponse = HTTP.post(
  'https://partner.example.com/api/sync',
  JSON.stringify({ email: request.params.email, consent: true }),
  {
    Authorization: `Bearer ${Nimbu.Site.env.get('PARTNER_TOKEN')}`,
    'Content-Type': 'application/json'
  }
);

if (syncResponse.code >= 400) {
  throw new Error(`Partner sync failed: ${syncResponse.code}`);
}

Limits And Network Policy

RuleValue
Total deadline per request (DNS, connect, TLS, request and body)15 seconds; 120 seconds inside a background job. Not configurable.
Response body size10 MB by default (can differ per plan)
Schemeshttp and https only
Ports80 and 443 only
RedirectsNever followed: a 3xx comes back as the response
CompressionAccept-Encoding: identity is always sent and can't be overridden. A gzip or deflate body sent anyway is decompressed under the same size cap.

Address checks:

  • The hostname is resolved once. If any resolved address is private, loopback, link-local (including the 169.254.169.254 cloud metadata address), multicast or otherwise reserved, the request is refused. IP-literal URLs get the same check.
  • The connection goes to the first checked address, so a DNS change between the check and the connection has no effect.
  • Proxies from the environment are ignored.

Credentials in the URL (https://user:pass@host/...) are sent as HTTP Basic auth. An Authorization header you set yourself wins over URL credentials.

The deadline is separate from the handler's own execution limit. In a route (10 seconds) a slow request hits the route limit before the 15 second HTTP deadline.

Failure Modes & Gotchas

Failures throw an Error you can catch:

MessageCause
invalid uriBlocked or malformed URL: wrong scheme or port, private or reserved address, or a host on the platform denylist.
timed out after 15.0s (or timed out)The deadline passed. In jobs the message says 120.0s.
response exceeds 10485760 bytesThe body was larger than the cap. The number is the cap for your plan.
DNS resolution failedThe hostname did not resolve.
TLS handshake or certificate verification failedTLS error or invalid certificate.
try {
  const response = HTTP.get('https://api.example.com/v1/report');
  // ...
} catch (error) {
  console.error('Report fetch failed:', error.message);
}
  • Follow redirects yourself if you need to: read headers.location from the 3xx response and make a new request.
  • For large exports, page through the remote API instead of downloading one big body.

On this page