Skip to content
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

Proposal: Request.json helper #1791

Open
denis-migdal opened this issue Dec 7, 2024 · 1 comment
Open

Proposal: Request.json helper #1791

denis-migdal opened this issue Dec 7, 2024 · 1 comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api

Comments

@denis-migdal
Copy link

What problem are you trying to solve?

Currently, we have a Response.json(obj, init) static method to build JSON Response, cf #1389

However, we do not seem to have a Request.json(url, obj, init) equivalent to build JSON Request.

What solutions exist today?

Setting body with JSON.stringify as well as the content-type header by hand :

new Request(url, {
    body: JSON.stringify(obj),
    headers: {
         "content-type": "application/json"
    }
});

How would you solve it?

I suggest adding a Request.json(url, obj, init) static method mirroring the Response.json(obj, init) static method.

Alternatively, it could be a Request.json(url, init) static method (the JS object then being given through init.body).

Anything else?

No response

@denis-migdal denis-migdal added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Dec 7, 2024
@Shivangbijalwan
Copy link

I think the second one is the good approch

Request.json(url, init)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api
Development

No branches or pull requests

3 participants