Skip to Content
Drash v3 is in beta. APIs may change.

ResponseBuilder

import { response } from "@drashland/drash/modules/builders/ResponseBuilder.js"; const res = response() .status(201) .statusText("Created") .headers({ "content-type": "application/json" }) .body(JSON.stringify({ id: 1 })) .build();

Returns a ResponseBuilder, which implements IBuilder<Response>.

MethodNotes
body(body)BodyInit | null
headers(headers)Record<string, string>. Merges, not replaces
status(status)number
statusText(text)string
build()Returns a Web Response

Every method except build() returns the builder, so calls chain in any order.

This is a convenience, not a requirement. A resource returning new Response(...) directly is equally valid, and on runtimes without Web Response this builder is not what you want.

Implements Standard’s Builder<Response>, not Core’s IBuilder.

Two of the pre-built middleware extend this class with their own subclass: ETagResponseBuilder and RateLimitResponseBuilder.

Last updated on