Skip to content

Commit

Permalink
Deserialize response from bytes of JSON text (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustFrederik authored Feb 15, 2024
1 parent cd06adf commit 9e93205
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ehttp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ehttp"
version = "0.4.0"
version = "0.4.1"
authors = ["Emil Ernerfeldt <emil.ernerfeldt@gmail.com>"]
description = "Minimal HTTP client for both native and WASM"
edition = "2018"
Expand Down
6 changes: 6 additions & 0 deletions ehttp/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ impl Response {
std::str::from_utf8(&self.bytes).ok()
}

#[cfg(feature = "json")]
/// Convenience for getting json body
pub fn json<T: serde::de::DeserializeOwned>(&self) -> serde_json::Result<T> {
serde_json::from_slice(self.bytes.as_slice())
}

/// Convenience for getting the `content-type` header.
pub fn content_type(&self) -> Option<&str> {
self.headers.get("content-type")
Expand Down

0 comments on commit 9e93205

Please sign in to comment.