Appearance
Results Proxy
The Results global is the HTTP response builder available in ingress handler scripts. Every method returns an IngressResult object that can be chained to set headers, status codes, and body content.
Quick Example
javascript
export function handleRequest(context) {
const data = { message: "Hello", timestamp: Date.now() };
return Results.json().renderRaw(JSON.stringify(data));
}Factory Methods
Each factory method creates a new IngressResult with a preset status code and content type:
| Method | Status | Content-Type |
|---|---|---|
Results.ok() | 200 | (default) |
Results.json() | 200 | application/json |
Results.html() | 200 | text/html |
Results.text() | 200 | text/plain |
Results.xml() | 200 | application/xml |
Results.created(url) | 201 | + Location header |
Results.noContent() | 204 | — |
Results.redirect(url) | 303 | + Location header |
Results.redirectTemporary(url) | 307 | + Location header |
Results.badRequest() | 400 | — |
Results.unauthorized() | 401 | — |
Results.forbidden() | 403 | — |
Results.notFound() | 404 | — |
Results.internalServerError() | 500 | — |
Results.TODO() | 501 | application/json |
Results.status(code) | custom | — |
Results.contentType(ct) | 200 | custom |
Chaining Methods
After calling a factory method, chain these to customize the response:
.status(code)
Override the HTTP status code.
javascript
return Results.json().status(202).renderRaw(JSON.stringify({ queued: true }));.json() / .html() / .text() / .xml()
Set the content type (can override the factory method's default).
javascript
return Results.ok().json().renderRaw(JSON.stringify(data));.contentType(ct)
Set a custom content type string.
javascript
return Results.ok().contentType("text/csv").renderRaw(csvContent);.addHeader(name, value)
Add a response header.
javascript
return Results.json()
.addHeader("X-Request-Id", requestId)
.addHeader("Cache-Control", "max-age=60")
.renderRaw(JSON.stringify(data));.renderRaw(body)
Set the raw response body. This is the preferred method for JSON responses — it sends the exact string you provide without any wrapping.
- Parameters:
body: string | byte[]
javascript
// JSON response — use renderRaw with JSON.stringify
return Results.json().renderRaw(JSON.stringify({ id: 1, name: "Widget" }));.render(body)
Set the response body directly. For HTML responses, pass the HTML string:
javascript
// HTML response
return Results.html().render("<h1>Hello, World!</h1>");.render(key, value)
Add a key-value pair to a rendered map. If you call .render(key, value) multiple times, the values accumulate in a map that becomes the response body.
javascript
return Results.ok()
.render("status", "ok")
.render("count", 42);
// Response body: { "status": "ok", "count": 42 }WARNING
For JSON responses, prefer renderRaw(JSON.stringify(obj)) over .render(key, value). The renderRaw approach gives you full control over the JSON output.
Body Resolution Order
renderRaw(body)orrender(body)(direct body) takes precedencerender(key, value)map (accumulated key-value pairs)- If neither is set, the body is
null
Common Patterns
JSON API Response
javascript
export function handleRequest(context) {
const items = ItemService.findAll();
return Results.json().renderRaw(JSON.stringify({
data: items,
count: items.length
}));
}Error Response
javascript
export function handleRequest(context) {
const id = context.getParameter("id");
if (!id) {
return Results.badRequest().json().renderRaw(
JSON.stringify({ error: "Missing 'id' parameter" })
);
}
// ...
}Redirect
javascript
export function handleRequest(context) {
return Results.redirect("/dashboard");
}Created with Location
javascript
export function handleRequest(context) {
const newId = ItemService.createItem(data);
return Results.created("/api/items/" + newId)
.json()
.renderRaw(JSON.stringify({ id: newId }));
}Custom Content Type
javascript
export function handleRequest(context) {
const csv = generateCsvReport();
return Results.ok()
.contentType("text/csv")
.addHeader("Content-Disposition", "attachment; filename=report.csv")
.renderRaw(csv);
}