diff --git a/ehttp/src/types.rs b/ehttp/src/types.rs index b69de81..f2a540f 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. @@ -250,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