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

Response.json() #741

Closed
ricea opened this issue May 20, 2022 · 6 comments
Closed

Response.json() #741

ricea opened this issue May 20, 2022 · 6 comments
Assignees
Labels

Comments

@ricea
Copy link

ricea commented May 20, 2022

Braw mornin' TAG!

I'm requesting a TAG review of Response.json().

Response.json(body) is a static method used to construct a Response object from the JSON serialisation of "body". It does what you would want new Response(body) to do if that was not ambiguous.

Further details:

  • [ X ] I have reviewed the TAG's Web Platform Design Principles
  • Relevant time constraints or deadlines: As we already have an implementation ready to land, we would like to ship this soon in Chromium.
  • The group where the work on this specification is currently being done: WHATWG
  • The group where standardization of this work is intended to be done (if current group is a community group or other incubation venue): WHATWG
  • Major unresolved issues with or opposition to this specification: None
  • This work is being funded by: Google is paying me to write this document. The implementation in Chromium was done by a third-party, as was the specification work.

You should also know that...

It is a very small feature.

We'd prefer the TAG provide feedback as (please delete all but the desired option):

💬 leave review feedback as a comment in this issue and @-notify ricea, annevk, lucacasonato

¹ We require an explainer to give the relevant context for the spec review, even if the spec has some background information. For background, see our explanation of how to write a good explainer. We recommend the explainer to be in Markdown.

² A Security and Privacy questionnaire helps us understand potential security and privacy issues and mitigations for your design, and can save us asking redundant questions. See https://www.w3.org/TR/security-privacy-questionnaire/.

@torgo
Copy link
Member

torgo commented May 25, 2022

Any chance you could publish the explainer and questionnaire responses in markdown along side of the spec please?

@ricea
Copy link
Author

ricea commented May 26, 2022

I've created Markdown versions at https://github.com/ricea/response-json-explainer.

@annevk how would you feel about including them in the fetch repository?

@annevk
Copy link
Member

annevk commented May 30, 2022

I could see adding an example to the standard. WHATWG standards are expected to be self-contained documents so I wouldn't really want to add separate markdown files that also need to be consulted/maintained.

@LeaVerou
Copy link
Member

LeaVerou commented Jul 18, 2022

Hi @ricea,

We took a look at this today during a breakout. While the functionality seems worthwhile, we are concerned that it might be confusing that there is an instance method and a static method with the same name that do exactly opposite things. This is also acknowledged in the explainer, but as a benefit:

This is symmetric with the Response.prototype.json() method which converts back the other way.

We are also unsure if it's a good idea to have a factory method whose naming does not indicate that it's a factory method.

What are your thoughts on this? What alternative names have you considered?

@LeaVerou LeaVerou added the Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review label Jul 18, 2022
@LeaVerou
Copy link
Member

LeaVerou commented Jul 26, 2022

Hi again. We looked at this again during a breakout today.

We still think that it's confusing if any static method could be a factory method, and we believe there is value in making this obvious with a naming convention. As an example, we explored ideas such as Response.from(value, options) with a dictionary argument whose type defaults to "json", which would be equally concise.

However, we see that there is precedent in having factory methods in this API whose names are simple nouns (Response.error(), Response.redirect()), and we think internal consistency within the API is more important than external consistency with the rest of the Web Platform, so we will go ahead and close this.

@LeaVerou LeaVerou added Resolution: satisfied The TAG is satisfied with this design and removed Progress: pending external feedback The TAG is waiting on response to comments/questions asked by the TAG during the review labels Jul 26, 2022
@ricea
Copy link
Author

ricea commented Jul 27, 2022

Thank you for the feedback. I like the idea of Response.from() but since most types can simply be passed to the constructor, it might turn out to be a misleadingly general name.

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

No branches or pull requests

7 participants