Response Class
The class is a wrapper around the native response object that provides additional functionality and convenience methods. It can map to either Node.js HTTP Server Response and WHATWG Response objects. The primary purpose is to provide a consistent API for handling responses, regardless of the underlying implementation. The response class is designed to work with several mediums including HTTP, WebSocket, CLI, etc. Serialized responses are objects and is useful when interchanging between and objects.
❐ Copy
body
Returns the response body. You can also manually set the body.
❐ Copy
❐ Copy
code
Returns the response code. Defaults to (zero). You can also manually set the code.
❐ Copy
❐ Copy
data
A callable nest that manages the response data. This is the data is arbitrary data not part of the serialized response. This is normally used as extra view props.
❐ Copy
dispatcher
Sets the dispatcher function. This function is called when the is called.
❐ Copy
error
Returns the error message. You can also manually set the error.
❐ Copy
❐ Copy
errors
A callable nest that manages the sub-errors.
❐ Copy
headers
A callable map that manages the response headers.
❐ Copy
mimetype
Returns the response mimetype. You can also manually set the mimetype.
❐ Copy
❐ Copy
redirected
Returns true if the response was redirected triggered by the method.
❐ Copy
resource
Returns the raw ServerResponse or Response object. It's also possible that there is no resource at all.
❐ Copy
sent
Returns true if the response was already dispatched.
❐ Copy
session
A callable session that manages the response session data. When using the or dispatcher, will set the cookies headers for the browser.
❐ Copy
stack
Returns an error stack (if available). You can also manually set the stack.
❐ Copy
❐ Copy
status
Returns the status message. You can also manually set the status.
❐ Copy
❐ Copy
total
Returns the total number of rows. This is useful for array results in order to figure out the pagination and other purposes. You can also manually set the total. Defaults to (zero).
❐ Copy
❐ Copy
type
Returns the type of body.
❐ Copy
dispatch()
Syncs the response with the native response if the is set.
❐ Copy
fromStatusResponse()
Loads the response from a object.
Usage
❐ Copy
Example
❐ Copy
redirect()
Adds a redirect header to the response.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
setBody()
Helper to rawly set the body of the response.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
setError()
Helper to set the response as an error response.
Usage
❐ Copy
❐ Copy
Example
❐ Copy
❐ Copy
setHTML()
Helper to set an HTML response.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
setJSON()
Helper to set a JSON response.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
setResults()
Helper to set the results of the response as a object as opposed to where the object is returned as is.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
setRows()
Helper to set the rows of the response as a object.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
setStatus()
Helper to set the status of the response.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
setXML()
Helper to set an XML response.
Usage
❐ Copy
Example
❐ Copy
❐ Copy
❐ Copy
stop()
When called, prevents the dispatcher from dispatching. This is useful if you want to manually handle the dispatch.
❐ Copy
toException()
Converts a response to an .
❐ Copy
toStatusResponse()
Converts the response to a object.
❐ Copy