diff --git a/Cargo.lock b/Cargo.lock index ecfe23b..b3c0c38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,7 +843,7 @@ dependencies = [ [[package]] name = "ehttp" -version = "0.4.0" +version = "0.4.1" dependencies = [ "async-channel", "document-features", diff --git a/ehttp/Cargo.toml b/ehttp/Cargo.toml index 4889f96..e50f2fc 100644 --- a/ehttp/Cargo.toml +++ b/ehttp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ehttp" -version = "0.4.0" +version = "0.4.1" authors = ["Emil Ernerfeldt "] description = "Minimal HTTP client for both native and WASM" edition = "2018" diff --git a/ehttp/src/types.rs b/ehttp/src/types.rs index ed3febd..419f31f 100644 --- a/ehttp/src/types.rs +++ b/ehttp/src/types.rs @@ -269,6 +269,12 @@ impl Response { std::str::from_utf8(&self.bytes).ok() } + #[cfg(feature = "json")] + /// Convenience for getting json body + pub fn json(&self) -> serde_json::Result { + 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")