import { json } from "https://deno.land/x/911@0.1.1/src/json.ts";
Create a new response in JSON format, with built-in error handling and
sensible defaults for the response headers. Accepts an optional second
parameter to configure the response output. It is typed as a union of
ResponseInit
and JSON.stringify
params 2 & 3.
Examples
Example 1
Example 1
import { json } from "https://deno.land/x/911@0.1.1/mod.ts";
import { STATUS_TEXT } from "https://deno.land/std/http/http_status.ts";
const response = json({
message: "Hello World",
});
// Equivalent to:
// new Response("{\"message\":\"Hello World\"}", {
// status: 200,
// headers: {
// "content-type": "application/json; charset=utf-8",
// "content-length": "17",
// "etag": "W/5c8qKJoE6P9Q",
// "access-control-allow-origin": "*",
// },
// });