Res
Response class that provides methods for sending HTTP responses with various formats and status codes.
Source
Type Definition
class Res {
  status(status: number): Res
  headers(headers: Record<string, string>): Res
  redirect(url: string, status?: number): Response
  send(data?: BodyInit): Response
  json(data: unknown): Response
  html(data: string | ReadableStream<Uint8Array>): Response
  text(data: string): Response
  cookie(name: string, value?: string | null, options?: CookieOptions): Res
}Methods
status
Sets the HTTP status code for the response.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
status | number | ✅ | - | HTTP status code (e.g., 200, 404, 500) | 
Returns
Res
headers
Sets multiple response headers.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
headers | Record<string, string> | ✅ | - | Object with header key-value pairs | 
Returns
Res
redirect
Sends a redirect response to the specified URL.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
url | string | ✅ | - | URL to redirect to | 
status | number | ❌ | 302 | HTTP redirect status code | 
Returns
Response
send
Sends a response with the specified data.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
data | BodyInit | ❌ | - | Response body data | 
Returns
Response
json
Sends a JSON response.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
data | unknown | ✅ | - | Data to serialize as JSON | 
Returns
Response
html
Sends an HTML response.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
data | string | ReadableStream<Uint8Array> | ✅ | - | HTML content to send | 
Returns
Response
text
Sends a plain text response.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
data | string | ✅ | - | Text content to send | 
Returns
Response
cookie
Sets or deletes a cookie.
Parameters
| Parameter | Type | Required | Default | Description | 
|---|---|---|---|---|
name | string | ✅ | - | Cookie name | 
value | string | null | ❌ | - | Cookie value (null to delete) | 
options | CookieOptions | ❌ | - | Cookie configuration options | 
Returns
Res
Last modified: 2025-06-10