$response
Updated on Aug 19, 2025 6 minutes to readThe Response Plugin provides methods to manage and send HTTP responses, including headers, cookies, files, and different content formats.
Methods
Method | Description |
---|---|
addHeader | Adds a new HTTP header to the response. |
getIsOk | Returns whether the response status is OK. |
redirect | Redirects the client to a given URL. |
removeCookie | Removes a cookie from the response. |
removeHeader | Removes a previously set HTTP header. |
send | Sends plain string data as the response. |
sendAsHtml | Sends a string as an HTML response. |
sendAsJson | Sends an object as a JSON response. |
sendAsXml | Sends an object as an XML response. |
sendContentAsFile | Sends raw content as a downloadable file. |
sendFile | Sends a file by ID or PDF object. |
sendMetadataImage | Sends a metadata image by script alias. |
sendPdfPageAsImage | Sends a specific PDF page as an image. |
setCookie | Sets a cookie in the response. |
setHeader | Sets (replaces) an HTTP header in the response. |
setStatusCode | Sets the HTTP status code and optional text. |
Methods Details
getIsOk()
• Type
() => boolean
• Details
Expects a string.
Sends it as the response body.
send()
• Type
(data: string) => void
• Details
Expects a string.
Sends it as the response body.
sendAsJson()
• Type
(data: any) => void
• Details
Expects any object or value.
Sends it as JSON with the appropriate Content-Type.
sendAsXml()
• Type
(data: any) => void
• Details
Expects any object or value.
Sends it as XML with the appropriate Content-Type.
sendAsHtml()
• Type
(data: string) => void
• Details
Expects a string.
Sends it as HTML with the appropriate Content-Type.
sendFile()
• Type
(id: string | Pdf, options?: SendFileOptions) => void
• Details
Expects either a file ID or a Pdf object,
and optional SendFileOptions. Sends the specified file as the response.
If the file is a Pdf object, the default options are: basename is the system file name, inline is true, mimeType is application/pdf.
For all other file types, the default options are: basename is the system file name, inline is false, mimeType is the file’s MIME type.
Sends the specified file as the response.
sendContentAsFile()
• Type
(
content: string,
basename: string,
options?: SendContentAsFileOptions
) => void
• Details
Expects raw content,
a file basename,
and optional SendContentAsFileOptions (default: {inline: false, mimeType: 'application/octet-stream'}
).
Sends the content as a downloadable file.
sendMetadataImage()
• Type
(scriptAlias: string, options?: SendFileOptions) => void
• Details
Expects a script alias and optional SendFileOptions (default options are: basename is the system file name, inline is false, mimeType is the file’s MIME type).
Sends the corresponding metadata image.
sendPdfPageAsImage()
• Type
(
id: string,
page: number,
options?: SendPdfPageOptions
) => void
• Details
Expects a file ID,
a page number,
and optional SendPdfPageOptions (default: {dpi: 72}
).
Sends the specified page of a PDF file as an image.
setHeader()
• Type
(name: string, value?: string) => void
• Details
Expects a header name and optional value (default: ''
).
Sets or replaces an HTTP header.
addHeader()
• Type
(name: string, value?: string) => void
• Details
Expects a header name and optional value (default: ''
).
Adds an HTTP header without replacing existing ones.
removeHeader()
• Type
(name: string) => void
• Details
Expects a header name.
Removes the specified HTTP header.
setCookie()
• Type
(cookie: Cookie) => void
• Details
Expects a Cookie object.
Adds the cookie to the response.
removeCookie()
• Type
(name: string, removeFromBrowser: boolean) => void
• Details
Expects a cookie name and a flag indicating if it should be removed from the browser.
Removes the cookie from the response.
redirect()
• Type
(url: string, statusCode?: number) => void
• Details
Expects a URL and optional status code (default: 302
).
Redirects the client to the given URL.
setStatusCode()
• Type
(statusCode: number, text?: string) => void
• Details
Expects a numeric HTTP status code and an optional text message (by default, the message corresponds to the provided status code).
Sets the response status code and message.