Return text, binary and HTML
How to send text, images, files or HTML from a function and read them back with the SDK or plain HTTP.
1. Choose a response type
| Your function returns | Use responseType | data is |
|---|---|---|
| JSON | 'json' (default) | the parsed value |
| Plain text, CSV, HTML | 'text' (or 'json', which also returns the string) | a string |
| An image, a PDF, any bytes | 'blob' or 'arrayBuffer' | a Blob or an ArrayBuffer |
The default 'json' mode can carry JSON and text. It cannot carry bytes: if a function answers with a binary content type, the SDK returns the error invalid_response and tells you to pick 'blob' or 'arrayBuffer', so nothing is lost silently.
2. Read it with the SDK
In a real run with a function returning the bytes 137,80,78,71,13,10,26,10,255,0,1, arrayBuffer returned exactly those 11 bytes and blob returned type=image/png size=11.
With 'text', 'blob' or 'arrayBuffer', the SDK skips the JSON envelope and returns the body of your function as it is. If your function answers with an error status, error.status is that status and error.message is the text your function returned.
3. Raw mode over HTTP
Add the header X-Aurabase-Invoke-Mode: raw and the platform returns your function's own response: its status, content-type and bytes.
Without that header, the response is always 200 with an envelope:
In the envelope, body is the parsed JSON, the text of your response when it is UTF-8 and not JSON, or null when the body is empty or binary.
In raw mode every response from your function carries x-aurabase-invoke-origin: function. A response without it comes from the gateway or the runtime. This is how the SDK tells a 503 returned by your code from a platform outage.
4. Which headers survive
In raw mode your response headers are filtered, because they are served from the platform's own origin.
| Header | Result |
|---|---|
content-type | Kept. Defaults to application/octet-stream if you set none. |
Custom headers (x-custom-out, cache-control, …) | Kept. |
set-cookie | Removed. A function cannot set cookies. |
access-control-* | Removed. CORS is decided by the gateway. |
x-aura-*, x-internal-token | Removed. |
content-security-policy, strict-transport-security, x-content-type-options | Set by the platform, whatever you send. |
content-length, transfer-encoding, connection | Recomputed. |
A response that can run scripts (text/html, application/xhtml+xml, image/svg+xml, application/xml, text/xml) is served with a sandboxing content security policy. Real response for a function returning text/html:
Your HTML is served, but without cookie, storage or script access to your project's origin. Use Storage or your own domain to host a real web page.