]> git.proxmox.com Git - proxmox.git/commitdiff
client: put requests
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 9 Aug 2023 12:53:39 +0000 (14:53 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 9 Aug 2023 13:29:38 +0000 (15:29 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-client/src/client.rs
proxmox-client/src/lib.rs

index 48b1a7a4bef7e2943475701ec78c255ba9051183..27d070287c9fa66c5c356f9665e0531a46080b1b 100644 (file)
@@ -363,6 +363,31 @@ impl HttpApiClient for Client {
         })
     }
 
+    fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize,
+    {
+        let params = serde_json::to_string(params)
+            .map_err(|err| Error::internal("failed to serialize parametres", err));
+
+        Box::pin(async move {
+            let params = params?;
+            let auth = self.login_auth()?;
+            let uri = self.build_uri(path_and_query)?;
+            let client = Arc::clone(&self.client);
+            Self::authenticated_request(client, auth, http::Method::PUT, uri, Some(params)).await
+        })
+    }
+
+    fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
+        Box::pin(async move {
+            let auth = self.login_auth()?;
+            let uri = self.build_uri(path_and_query)?;
+            let client = Arc::clone(&self.client);
+            Self::authenticated_request(client, auth, http::Method::PUT, uri, None).await
+        })
+    }
+
     fn delete<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a> {
         Box::pin(async move {
             let auth = self.login_auth()?;
index 54e655aeca2901b61c0549a3170ba899089c0bc1..f8fa273e9e9aae2fb5be13d9136c7cf84fbbd004 100644 (file)
@@ -41,6 +41,20 @@ pub trait HttpApiClient: Send + Sync {
     where
         T: ?Sized + Serialize;
 
+    /// `PUT` request with a path and query component (no hostname), and a serializable body.
+    ///
+    /// The body should be serialized to json and sent with `Content-type: applicaion/json`.
+    ///
+    /// For this request, authentication headers should be set!
+    fn put<'a, T>(&'a self, path_and_query: &'a str, params: &T) -> Self::ResponseFuture<'a>
+    where
+        T: ?Sized + Serialize;
+
+    /// `PUT` request with a path and query component (no hostname), no request body.
+    ///
+    /// For this request, authentication headers should be set!
+    fn put_without_body<'a>(&'a self, path_and_query: &'a str) -> Self::ResponseFuture<'a>;
+
     /// `DELETE` request with a path and query component (no hostname).
     ///
     /// For this request, authentication headers should be set!