Res
A wrapper for the response object with helper methods and access to Autonym model data.
Static Member Summary
Static Public Members | ||
public static |
The status code for successful create calls. |
|
public static |
The status code for successful find, findOne, findOneAndUpdate, and findOneAndDelete calls. |
Constructor Summary
Public Constructor | ||
public |
constructor(raw: http.ServerResponse, model: Model, meta: Meta) |
Method Summary
Public Methods | ||
public |
Gets the data currently set for the response body. |
|
public |
Gets the given header. |
|
public |
Gets the model instance. |
|
public |
getRaw(): http.ServerResponse Gets the raw response. |
|
public |
Gets the currently set status code. |
|
public |
Whether the store method has populated the response data yet. |
|
public |
Whether the response has been sent to the client. |
|
public |
Merges the currently set response data with the given data. |
|
public |
Sets the given header. |
|
public |
Sets the status code. |
Static Public Members
Public Constructors
Public Methods
public getData(): Record source
Gets the data currently set for the response body.
Throw:
If the store method has not been called yet. |
public getHeader(header: string): string | undefined source
Gets the given header.
Params:
Name | Type | Attribute | Description |
header | string | The header to find. |
public getRaw(): http.ServerResponse source
Gets the raw response.
Return:
http.ServerResponse | The raw response. |
public setData(data: Record, replace: boolean): void source
Merges the currently set response data with the given data.
Return:
void |
Throw:
If the store method has not been called yet. |
Example:
console.log(res.getData()) // { title: 'Hello World' }
res.setData({ name: 'Test' })
console.log(res.getData()) // { name: 'Test', title: 'Hello World' }
console.log(res.getData()) // { title: 'Hello World' }
res.setData({ name: 'Test' }, true)
console.log(res.getData()) // { name: 'Test' }