Function customResponse

Creates a custom response with the specified body, content type, and options.

  • Parameters

    • body: BodyInit

      The response body, which can be of type BodyInit or null.

    • contentType: string = ""

      The Content-Type header for the response. Defaults to an empty string.

    • options: ResponseInit = {}

      Optional response initialization options.

    Returns Response

    A Response object with the specified body, headers, and options.

    Example usage:

    import { start, router, customResponse } from "@pulsar-http/core";

    const routes = [
    router.get("/api/users", async () => customResponse(JSON.stringify({ users: [] }), "application/json", { headers: { "X-Test": "123" } })),
    ];

    start({ routes });

    In this example, the response will have a JSON body, a Content-Type header of "application/json" and a custom "X-Test" header.