From d3543c1ce3af7378a8704622fc336e9235beb9ab Mon Sep 17 00:00:00 2001 From: pintariching Date: Mon, 8 Dec 2025 18:26:20 +0100 Subject: [PATCH 1/2] Add PUT and DELETE methods to Request struct --- ehttp/src/types.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ehttp/src/types.rs b/ehttp/src/types.rs index b69de81..e18971f 100644 --- a/ehttp/src/types.rs +++ b/ehttp/src/types.rs @@ -197,6 +197,34 @@ impl Request { } } + /// Create a 'PUT' request with the given url and body. + #[allow(clippy::needless_pass_by_value)] + pub fn put(url: impl ToString, body: Vec) -> Self { + Self { + method: "PUT".to_owned(), + url: url.to_string(), + body, + headers: Headers::new(&[ + ("Accept", "*/*"), + ("Content-Type", "text/plain; charset=utf-8"), + ]), + mode: Mode::default(), + timeout: Some(Self::DEFAULT_TIMEOUT), + } + } + + /// Create a 'DELETE' request with the given url. + pub fn delete(url: &str) -> Self { + Self { + method: "DELETE".to_owned(), + url: url.to_string(), + body: vec![], + headers: Headers::new(&[("Accept", "*/*")]), + mode: Mode::default(), + timeout: Some(Self::DEFAULT_TIMEOUT), + } + } + /// Multipart HTTP for both native and WASM. /// /// Requires the `multipart` feature to be enabled. From 902c18b07fdb64f9091dd32886b9118f361af1dc Mon Sep 17 00:00:00 2001 From: pintariching Date: Mon, 8 Dec 2025 18:26:56 +0100 Subject: [PATCH 2/2] Add put_json method to Request struct --- ehttp/src/types.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ehttp/src/types.rs b/ehttp/src/types.rs index e18971f..f2a540f 100644 --- a/ehttp/src/types.rs +++ b/ehttp/src/types.rs @@ -278,6 +278,23 @@ impl Request { }) } + #[cfg(feature = "json")] + /// Create a 'PUT' request with the given url and json body. + #[allow(clippy::needless_pass_by_value)] + pub fn put_json(url: impl ToString, body: &T) -> serde_json::error::Result + where + T: ?Sized + Serialize, + { + Ok(Self { + method: "PUT".to_owned(), + url: url.to_string(), + body: serde_json::to_string(body)?.into_bytes(), + headers: Headers::new(&[("Accept", "*/*"), ("Content-Type", "application/json")]), + mode: Mode::default(), + timeout: Some(Self::DEFAULT_TIMEOUT), + }) + } + pub fn with_timeout(mut self, timeout: Option) -> Self { self.timeout = timeout; self