The Response Web API allows you to construct a Response object to be returned in your webhook handler, but also represents the received response for your fetch requests and gives you access to the response’s headers, body and other properties.


declare class Response extends Body {
  constructor(bodyInit?: BodyInit | null, maybeInit?: ResponseInit | Response);
  static redirect(url: string, status?: number): Response;
  static json(any: any, maybeInit?: ResponseInit | Response): Response;
  clone(): Response;
  readonly status: number;
  readonly statusText: string;
  readonly headers: Headers;
  readonly ok: boolean;
  readonly redirected: boolean;
  readonly url: string;
  readonly webSocket: WebSocket | null;
  readonly cf?: Object;


  • Response(): Response
    • The Response() constructor creates a new Response object.


  • body: ReadableStream
    • A ReadableStream representing the request’s body. This can be accessed via helper methods such as text() and json().

  • bodyUsed: boolean
    • A boolean used to tell if the body has been consumed or not.

      Example Usage
      Example: bodyUsed
      export default {
      	async webhook(req: Request, env: Repeat.Env) {
      		const res = await fetch("");
      		console.log(res.bodyUsed); // false
      		const body = await res.text();
      		console.log(res.bodyUsed); // true
      		const body2 = await res.text(); // Exception: body has already been used.
  • status: Number
    • Represents the HTTP status code of the response.

  • statusText: string
    • Represents the text associated with a HTTP status code, such as NOT FOUND for a 404 status code.

  • headers: Headers
    • A Headers object used by the the response. Headers cannot be accessed via indexing, such as headers["content-type"], and instead expose methods such as get() or set().

      Example Usage
      export default {
      	async webhook(request: Request) {
      		const response = await fetch("");
      		const contentType = response.headers.get("Content-Type");
      		if (contentType) {
      			console.log(`Response's Content-Type is: ${contentType}`);
  • ok: boolean
    • A boolean representing if the request was successful.

  • redirected: boolean
    • Represents if the response is the result of a redirect.

  • url: string
    • The final URL of where the response was received from.


  • clone() → Response
    • Creates a cloned instance of the Response object.

  • redirect() → Response
    • Return a redirect to the provided URL.

  • json() → Response
    • Return a JSON response which is the result of calling JSON.stringify on the provided object. The JSON is not pretty-printed.


Return a response from your handler

Example #1
export default {
	async webhook(request: Request, env: Repeat.Env) {
		return new Response("Hello world!")

Last updated on November 20, 2022