#741: Response.json()
Discussions
2022-07-18
Lea: we can wait for external feedback.
Dan: WebXRraw camera access <- closed and a good example where we have had an impact.
Rossen: seconded.
2022-07-18
Lea: one of my concerns here - a static method that has the same name as an instance method and does something completely different. Response.prototype.json (the instance method) converts the response to json - this one takes an object and converts it to a response, i.e. the inverse. Should it be a concern? I think it's a bit confusing. In general i expect when instance methods and static methods have the same name then they are related. Feels like an antipattern?
Dan: would it be better to have 'fromJson'?
Lea: then inconsistent with the other method which is also
Lea: e.g. Response.json(response.json())
would be confusing... I wonder if there's a precedent on the web platform... single words for names - in general a good thing - because we don't want extremely verbose names - but breaks down in cases like this. We could use toJSON and fromJSON... Also don't know if it makes sense to hold it up on naming. We should decide what pattern what should be followed... when you invert that type of function.
Peter: fromJSON wouldn't apply because you're not passing JSON into it... toJSON doesn't apply either...
Lea: the existing instance method gives you an object and this does the reverse.
Peter: at the end of the day it's a factory method
Lea: and nothing indicates this.
Peter: agree the naming is ambiguous - but I would name it something that indicates it's a factory.
let's go to the bat-design-principles
nothing there right now
Lea: "create" is the dominant convention in other platforms. Should we have a principle that factory metods should have a "create"?
Dan: can we ask them to comment on this?
Lea: i will leave a comment.
OpenedMay 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 wantnew Response(body)
to do if that was not ambiguous.Further details:
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/.