Skip to content

Commit b17754f

Browse files
committed
Response.json as per whatwg/fetch#1389
1 parent 4916abd commit b17754f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/response.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ class Response extends Body {
7878
return response;
7979
}
8080

81+
static json(body: unknown, init?: ResponseInit) {
82+
const headers = new Headers(init?.headers);
83+
if (!headers.has("Content-Type")) {
84+
headers.set("Content-Type", "application/json");
85+
}
86+
return new Response(body, {
87+
...init,
88+
headers
89+
});
90+
}
91+
8192
}
8293

8394
export { Response };

0 commit comments

Comments
 (0)