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

x/drash/src/modules/builders/ResponseBuilder.ts>ResponseBuilder

A microframework for building JavaScript HTTP applications. Runtime-agnostic. Strongly typed.
Latest
class ResponseBuilder
implements Builder<Response>
import { ResponseBuilder } from "https://deno.land/x/drash@v3.0.0-beta.2/src/modules/builders/ResponseBuilder.ts";

A builder to help build a Response object. This is useful if the response's data needs to be modified throughout a lifecycle, but not instantiated into a Response object until required.

Examples

Example 1

const builder = new ResponseBuilder();

// This call ...
const resA = builder
  .headers({
    "x-some-header": "Some Value"
    "x-some-other-header": "Some Other Value",
  })
  .body("Nope.")
  .status(400)
  .statusText("Bad Request")
  .build();

// ... results in the same response as this call ...
const resB = new Response("Nope.", {
  status: 400,
  statusText: "Bad Request",
  headers: {
    "x-some-header": "Some Value"
    "x-some-other-header": "Some Other Value",
  }
})

Properties

protected
response_body: BodyInit | null
protected
response_headers: Headers
protected
response_init: ResponseInit

Methods

body(body: BodyInit | null)

Set the body the built response will use as its BodyInit.

headers(headers: Record<string, string>)

Set the headers (using key-value pairs) the built response will use as its ResponseInit.headers.

status(status: number)

Set the status the built response will use as its ResponseInit.status.

statusText(statusText: string)

Set the ResponseInit.statuText property.