HttpOutgoing
HttpOutgoing is the outgoing HTTP response interface used throughout OPRA. It extends NodeOutgoingMessage with Express-compatible helpers for cookies, redirects, content type, and response status.
import { HttpOutgoing } from '@opra/http';
In operation handlers ctx.response is an HttpOutgoing. See HttpContext. In most OPRA handlers you return a value rather than writing to the response directly — use ctx.response only when you need full control.
Methods
status(code)
status(code: number): this
Sets the HTTP status code. Chainable.
ctx.response.status(201).send(newCustomer);
send(body?)
send(body?: any): this
Sends the response. Accepts a string, Buffer, or object (serialized to JSON).
sendStatus(code)
sendStatus(code: number): this
Sets the status code and sends the standard status text as the response body.
ctx.response.sendStatus(204); // → "No Content"
redirect(url) / redirect(status, url)
redirect(url: string): void
redirect(status: number, url: string): void
Sends a redirect response. Defaults to 302 when status is omitted.
ctx.response.redirect(301, 'https://new.example.com/api');
attachment(filename?)
attachment(filename?: string): this
Sets the Content-Disposition header to attachment, triggering a file download in the browser.
ctx.response.attachment('report.pdf').send(pdfBuffer);
cookie(name, val, options?) / clearCookie(name, options?)
cookie(name: string, val: any, options?: CookieOptions): this
clearCookie(name: string, options?: CookieOptions): this
Sets or clears a Set-Cookie response header. CookieOptions → see Interfaces.
contentType(type)
contentType(type: string): this
Sets the Content-Type header. Accepts a MIME type, extension ('json', 'html'), or dotted extension ('.png').
location(url)
location(url: string): this
Sets the Location response header.
links(links)
links(links: Record<string, string>): this
Sets the Link response header from a map of relation → URL pairs.
ctx.response.links({
next: '/api/customers?skip=20',
prev: '/api/customers?skip=0',
});
Header management
setHeader(name: string, value: number | string | readonly string[]): this
getHeader(name: string): number | string | string[] | undefined
appendHeader(name: string, value: string | readonly string[]): this
Standard header management. setHeader replaces; appendHeader adds to an existing value.
Namespace
HttpOutgoing.from(instance)
HttpOutgoing.from(
instance: HttpOutgoing | NodeOutgoingMessage.Initiator
): HttpOutgoing
Factory that creates or upgrades an object into a full HttpOutgoing instance. If instance is already an HttpOutgoing it is returned as-is.
Interfaces
CookieOptions
| Option | Type | Description |
|---|---|---|
secret | string | Secret used for signing. |
maxAge | number | Max-age in milliseconds. |
signed | boolean | Sign the cookie value. |
expires | Date | Absolute expiry date. |
httpOnly | boolean | Prevents client-side JavaScript access. |
path | string | Cookie path. Defaults to '/'. |
domain | string | Cookie domain. |
secure | boolean | Only sent over HTTPS. |
encode | (val: string) => string | Custom encoding function for the cookie value. |
sameSite | boolean | 'lax' | 'strict' | 'none' | SameSite policy. |