Skip to content

Proposal: Request.json helper #1791

Open
@denis-migdal

Description

@denis-migdal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions