Response class provides methods for sending HTTP responses, setting headers, cookies, and managing response data.
Importing
Properties
Whether the response has been sent
Whether the response is pending
Whether headers have been sent
Sending Responses
send()
Send a response body.Response body (string, object, buffer, stream)
void
json()
Send a JSON response.Data to serialize as JSON
void
jsonp()
Send a JSONP response.Data to serialize as JSONP
JSONP callback function name
void
stream()
Stream a response.Readable stream to pipe
void
download()
Download a file.Path to the file
Optional filename for download
void
attachment()
Download a file with a custom name.Path to the file
Filename for download
void
Status Codes
status()
Set the response status code.HTTP status code
this
getStatus()
Get the current status code.number
safeStatus()
Set status code if not already set.HTTP status code
this
Status Helpers
ok()
Send a 200 OK response.Response body
void
created()
Send a 201 Created response.Response body
void
accepted()
Send a 202 Accepted response.Response body
void
noContent()
Send a 204 No Content response.void
badRequest()
Send a 400 Bad Request response.Response body
void
unauthorized()
Send a 401 Unauthorized response.Response body
void
forbidden()
Send a 403 Forbidden response.Response body
void
notFound()
Send a 404 Not Found response.Response body
void
methodNotAllowed()
Send a 405 Method Not Allowed response.Response body
void
conflict()
Send a 409 Conflict response.Response body
void
unprocessableEntity()
Send a 422 Unprocessable Entity response.Response body
void
internalServerError()
Send a 500 Internal Server Error response.Response body
void
Redirects
redirect()
Redirect to a URL.URL to redirect to
HTTP status code for redirect
void
redirectToRoute()
Redirect to a named route.Name of the route
Route parameters
Additional options (qs, domain)
void
back()
Redirect back to the previous URL.void
withQs()
Add query string to redirect.Query string parameters
this
clearQs()
Clear query string from redirect.this
Headers
header()
Set a response header.Header name
Header value
this
append()
Append a value to a header.Header name
Header value
this
removeHeader()
Remove a response header.Header name
this
getHeader()
Get a response header value.Header name
string | string[] | undefined
Content Type
type()
Set the Content-Type header.Content type or file extension
Optional character set
this
vary()
Set the Vary header.Header field name
this
Cookies
cookie()
Set a signed cookie.Cookie name
Cookie value
Cookie options
maxAge: Max age in secondshttpOnly: HTTP only flagsecure: Secure flagsameSite: SameSite policypath: Cookie pathdomain: Cookie domain
this
plainCookie()
Set a plain (unsigned) cookie.Cookie name
Cookie value
Cookie options
this
encryptedCookie()
Set an encrypted cookie.Cookie name
Cookie value
Cookie options
this
clearCookie()
Clear a cookie.Cookie name
this
Caching
fresh()
Check if the response should be fresh.boolean
etag()
Set the ETag header.ETag value
Use weak ETag
this
notModified()
Send a 304 Not Modified response.void