Skip to content

Implement Response.json if brought into spec. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fabiancook opened this issue Jan 28, 2022 · 1 comment
Closed

Implement Response.json if brought into spec. #3

fabiancook opened this issue Jan 28, 2022 · 1 comment

Comments

@fabiancook
Copy link
Member

A proof of concept can be seen in the feature/json branch

static json(body: unknown, init?: ResponseInit) {
const headers = new Headers(init?.headers);
if (!headers.has("Content-Type")) {
headers.set("Content-Type", "application/json");
}
return new Response(JSON.stringify(body), {
...init,
headers
});
}

Tracking whatwg/fetch/issues/1389 updates before merging.

@fabiancook
Copy link
Member Author

Closed by #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant