Naming Bikeshed: Response::into_{json,xml}_body
#1957
Labels
design-discussion
An area of design currently under discussion and open to team and community feedback.
#1954 introduces two new methods on
Response
:Response::<T>::into_json_body<U: DeserializeOwned>(self) -> crate::Result<U>
Response::<T>::into_xml_body<U: DeserializeOwned>(self) -> crate::Result<U>
The purpose of these methods is to consume the
Response
, stream the entire body, and deserialize it to the provided model typeU
, using either JSON or XML serde deserialization.The method name isn't ideal,
into
properly implies consuming theResponse
to produce a new type, but the{json,xml}_body
implies that it's "returning" JSON or XML somehow, when actually it's using JSON/XML deserialization to produce a model type.However, we also have methods
into_raw_body
andinto_body
for returning a rawResponseBody
and aT: Model
, which make more sense. Both are consuming theResponse
to produce a (potentially "raw") representation of the body. Theinto_{json,xml}_body
methods align with the convention established by those methods.We decided to move forward without resolving this naming conflict, so this issue exists to have a place to revisit it prior to a GA release, after which name changes would be much more costly.
Some potential ideas for discussion:
into_body_from_{json,xml}
is more accurate, but verbosebody_from_{json,xml}
loses theinto_
prefix, which has meaning in Rustparse_{json,xml}
is more accurate, relatively terse, but does still lose theinto_
prefixinto_{json,xml}_model
may be clearer, since it indicates the model is defined by JSON or XML rather than implying it returns the "body". We could similarly renameinto_body
tointo_model
🤔cc @heaths
The text was updated successfully, but these errors were encountered: