openai_interface/rest/
delete.rs1use std::{future::Future, str::FromStr};
4
5use serde::de::DeserializeOwned;
6
7use crate::errors::OapiError;
8
9pub trait Delete {
10 fn build_url(&self, base_url: &str) -> Result<String, OapiError>;
15}
16
17pub trait DeleteNoStream: Delete + Send + Sync {
18 type Response: DeserializeOwned + FromStr<Err = OapiError> + Send + Sync;
19
20 fn get_response_string(
25 &self,
26 client: &reqwest::Client,
27 base_url: &str,
28 key: &str,
29 ) -> impl Future<Output = Result<String, OapiError>> + Send + Sync {
30 async move {
31 let url = self.build_url(base_url)?;
32
33 let response = client
34 .delete(url)
35 .header("Accept", "application/json")
36 .bearer_auth(key)
37 .send()
38 .await?;
39
40 crate::rest::response_text_checked(response).await
41 }
42 }
43
44 fn get_response(
46 &self,
47 client: &reqwest::Client,
48 base_url: &str,
49 key: &str,
50 ) -> impl Future<Output = Result<Self::Response, OapiError>> + Send + Sync {
51 async move {
52 let text = self.get_response_string(client, base_url, key).await?;
53 let result = Self::Response::from_str(&text)?;
54 Ok(result)
55 }
56 }
57}