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

Unified body encoders/decoders #211

Open
sagebind opened this issue Jul 21, 2020 · 0 comments
Open

Unified body encoders/decoders #211

sagebind opened this issue Jul 21, 2020 · 0 comments
Labels
feature A new feature!

Comments

@sagebind
Copy link
Owner

Currently we offer text decoding and JSON serialization as extensions to the base API which are convenient for users, but they aren't very extensible. They also depend on the response body type, which it would be nice to make that more generalized. In addition, these usually read & consume the response stream as a read_to_end-like API, but it could be more ergonomic to return a Response<T> instead. For example:

  • Decoding text is a function that takes a Response<Body> and produces a Response<String>
  • Deserializing JSON (or some other Serde format) is a function that takes a Response<Body> and produces a Response<T> where T: Deserialize

We could redesign serialization a bit to make it more general like above and allow users to easily plug in their own formats without needing to manually serialize and deserialize bodies on every request; perhaps some trait you can implement and then attach to an HttpClient for some content type.

Thinking generally, deserialization often just requires knowing the content type on the response (or some extra headers like content encoding), but serialization usually needs some way for the user to explicitly specify how to serialize. I'm not exactly sure how this will be done yet, but it is worth thinking about.

@sagebind sagebind mentioned this issue Jul 29, 2020
8 tasks
@sagebind sagebind added the feature A new feature! label Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature!
Projects
None yet
Development

No branches or pull requests

1 participant