Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/ghst/res.ts>HTTPResponse

A light-weight http framework built for Deno.
Latest
class HTTPResponse
import { HTTPResponse } from "https://deno.land/x/ghst@v1.1.4/res.ts";

Constructors

new
HTTPResponse(requestEvent: Deno.RequestEvent)

Properties

private
_called: boolean
private
_requestEvent: Deno.RequestEvent
body: ResponseBody

The body of the response.

readonly
headers: Record<string, string>

Headers the response has.

status: number

Status code of the response.

Methods

end()

Sends the request. If not called then will automatically be called.

json(content: any)

Responds to the request with a JSON object. Use send or append instead, does the same now.

redirect(url: string)

Redirects the response using the Location header. Also sets the status to 308 so the request method doesn't change when redirected.

render(path: string, values: Record<string, string>)

Reads a file and replaces text with specified values.

send(content: ResponseBody)

Updates the body of the response.

sendFile(path: string)

Sets the body of the response to be the contents of a file.

setHeader(name: string, value: string)

Adds a header to the response.

setStatus(code: number)

Sets the status code of the response.