covenix / HttpResponse
Class: HttpResponse<T>
Defined in: src/http-response.ts:34
A JSON response that carries HTTP metadata — status, headers, cookies — alongside the body, so a handler can set them by returning a value instead of reaching for the raw Express res via @Res(). The body is still validated and serialized against the matched @Returns schema, exactly like a bare return; this only adds the surrounding metadata.
Returning one is opt-in: a handler may return T or HttpResponse<T>.
statusselects which declared@Returnsto send (must be one of them); defaults to the route's success status.headersare set on the response; a header matching a declared@Returns(..., { headers })schema is validated against it, and numbers are stringified. Undeclared headers are allowed.cookiesare emitted asSet-Cookie(Express does the formatting).
Example
@Get('me')
@Returns(200, UserSchema, { headers: { 'X-RateLimit-Remaining': z.number().int() } })
me(@Principal() user: User): HttpResponse<User> {
return new HttpResponse(user, {
headers: { 'X-RateLimit-Remaining': 42 }, // → "42"
cookies: [{ name: 'sid', value: token, options: { httpOnly: true, sameSite: 'lax' } }],
});
}Extends
Type Parameters
T
T = unknown
Constructors
Constructor
new HttpResponse<
T>(body,options?):HttpResponse<T>
Defined in: src/http-response.ts:38
Parameters
body
T
options?
ResponseBaseOptions = {}
Returns
HttpResponse<T>
Overrides
Properties
body
readonlybody:T
Defined in: src/http-response.ts:36
The response body — validated/serialized against the matched @Returns schema.
cookies
readonlycookies:ResponseCookie[] |undefined
Defined in: src/response.ts:63
Cookies to set (each its own Set-Cookie), if any.
Inherited from
headers
readonlyheaders:Record<string,HeaderValue> |undefined
Defined in: src/response.ts:61
Extra response headers, if set.
Inherited from
status
readonlystatus:number|undefined
Defined in: src/response.ts:59
Explicit HTTP status, if set.
