fastly_api/apis/
http3_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`create_http3`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateHttp3Params {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    pub service_id2: Option<String>,
22    pub version: Option<i32>,
23    /// Date and time in ISO 8601 format.
24    pub created_at: Option<String>,
25    /// Date and time in ISO 8601 format.
26    pub deleted_at: Option<String>,
27    /// Date and time in ISO 8601 format.
28    pub updated_at: Option<String>,
29    /// Revision number of the HTTP/3 feature implementation. Defaults to the most recent revision.
30    pub feature_revision: Option<i32>
31}
32
33/// struct for passing parameters to the method [`delete_http3`]
34#[derive(Clone, Debug, Default)]
35pub struct DeleteHttp3Params {
36    /// Alphanumeric string identifying the service.
37    pub service_id: String,
38    /// Integer identifying a service version.
39    pub version_id: i32
40}
41
42/// struct for passing parameters to the method [`get_http3`]
43#[derive(Clone, Debug, Default)]
44pub struct GetHttp3Params {
45    /// Alphanumeric string identifying the service.
46    pub service_id: String,
47    /// Integer identifying a service version.
48    pub version_id: i32
49}
50
51
52/// struct for typed errors of method [`create_http3`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum CreateHttp3Error {
56    UnknownValue(serde_json::Value),
57}
58
59/// struct for typed errors of method [`delete_http3`]
60#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum DeleteHttp3Error {
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`get_http3`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum GetHttp3Error {
70    UnknownValue(serde_json::Value),
71}
72
73
74/// Enable HTTP/3 (QUIC) support for a particular service and version.
75pub async fn create_http3(configuration: &mut configuration::Configuration, params: CreateHttp3Params) -> Result<crate::models::Http3, Error<CreateHttp3Error>> {
76    let local_var_configuration = configuration;
77
78    // unbox the parameters
79    let service_id = params.service_id;
80    let version_id = params.version_id;
81    let service_id2 = params.service_id2;
82    let version = params.version;
83    let created_at = params.created_at;
84    let deleted_at = params.deleted_at;
85    let updated_at = params.updated_at;
86    let feature_revision = params.feature_revision;
87
88
89    let local_var_client = &local_var_configuration.client;
90
91    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/http3", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
92    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
95        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
96    }
97    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
98        let local_var_key = local_var_apikey.key.clone();
99        let local_var_value = match local_var_apikey.prefix {
100            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
101            None => local_var_key,
102        };
103        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
104    };
105    let mut local_var_form_params = std::collections::HashMap::new();
106    if let Some(local_var_param_value) = service_id2 {
107        local_var_form_params.insert("service_id", local_var_param_value.to_string());
108    }
109    if let Some(local_var_param_value) = version {
110        local_var_form_params.insert("version", local_var_param_value.to_string());
111    }
112    if let Some(local_var_param_value) = created_at {
113        local_var_form_params.insert("created_at", local_var_param_value.to_string());
114    }
115    if let Some(local_var_param_value) = deleted_at {
116        local_var_form_params.insert("deleted_at", local_var_param_value.to_string());
117    }
118    if let Some(local_var_param_value) = updated_at {
119        local_var_form_params.insert("updated_at", local_var_param_value.to_string());
120    }
121    if let Some(local_var_param_value) = feature_revision {
122        local_var_form_params.insert("feature_revision", local_var_param_value.to_string());
123    }
124    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
125
126    let local_var_req = local_var_req_builder.build()?;
127    let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129    if "POST" != "GET" && "POST" != "HEAD" {
130      let headers = local_var_resp.headers();
131      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
132          Some(v) => v.to_str().unwrap().parse().unwrap(),
133          None => configuration::DEFAULT_RATELIMIT,
134      };
135      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
136          Some(v) => v.to_str().unwrap().parse().unwrap(),
137          None => 0,
138      };
139    }
140
141    let local_var_status = local_var_resp.status();
142    let local_var_content = local_var_resp.text().await?;
143
144    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
145        serde_json::from_str(&local_var_content).map_err(Error::from)
146    } else {
147        let local_var_entity: Option<CreateHttp3Error> = serde_json::from_str(&local_var_content).ok();
148        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
149        Err(Error::ResponseError(local_var_error))
150    }
151}
152
153/// Disable HTTP/3 (QUIC) support for a particular service and version.
154pub async fn delete_http3(configuration: &mut configuration::Configuration, params: DeleteHttp3Params) -> Result<crate::models::InlineResponse200, Error<DeleteHttp3Error>> {
155    let local_var_configuration = configuration;
156
157    // unbox the parameters
158    let service_id = params.service_id;
159    let version_id = params.version_id;
160
161
162    let local_var_client = &local_var_configuration.client;
163
164    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/http3", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
165    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
166
167    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
168        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
169    }
170    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
171        let local_var_key = local_var_apikey.key.clone();
172        let local_var_value = match local_var_apikey.prefix {
173            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
174            None => local_var_key,
175        };
176        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
177    };
178
179    let local_var_req = local_var_req_builder.build()?;
180    let local_var_resp = local_var_client.execute(local_var_req).await?;
181
182    if "DELETE" != "GET" && "DELETE" != "HEAD" {
183      let headers = local_var_resp.headers();
184      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
185          Some(v) => v.to_str().unwrap().parse().unwrap(),
186          None => configuration::DEFAULT_RATELIMIT,
187      };
188      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
189          Some(v) => v.to_str().unwrap().parse().unwrap(),
190          None => 0,
191      };
192    }
193
194    let local_var_status = local_var_resp.status();
195    let local_var_content = local_var_resp.text().await?;
196
197    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198        serde_json::from_str(&local_var_content).map_err(Error::from)
199    } else {
200        let local_var_entity: Option<DeleteHttp3Error> = serde_json::from_str(&local_var_content).ok();
201        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
202        Err(Error::ResponseError(local_var_error))
203    }
204}
205
206/// Get the status of HTTP/3 (QUIC) support for a particular service and version.
207pub async fn get_http3(configuration: &mut configuration::Configuration, params: GetHttp3Params) -> Result<crate::models::Http3, Error<GetHttp3Error>> {
208    let local_var_configuration = configuration;
209
210    // unbox the parameters
211    let service_id = params.service_id;
212    let version_id = params.version_id;
213
214
215    let local_var_client = &local_var_configuration.client;
216
217    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/http3", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
218    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
219
220    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
221        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
222    }
223    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
224        let local_var_key = local_var_apikey.key.clone();
225        let local_var_value = match local_var_apikey.prefix {
226            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
227            None => local_var_key,
228        };
229        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
230    };
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    if "GET" != "GET" && "GET" != "HEAD" {
236      let headers = local_var_resp.headers();
237      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
238          Some(v) => v.to_str().unwrap().parse().unwrap(),
239          None => configuration::DEFAULT_RATELIMIT,
240      };
241      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
242          Some(v) => v.to_str().unwrap().parse().unwrap(),
243          None => 0,
244      };
245    }
246
247    let local_var_status = local_var_resp.status();
248    let local_var_content = local_var_resp.text().await?;
249
250    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
251        serde_json::from_str(&local_var_content).map_err(Error::from)
252    } else {
253        let local_var_entity: Option<GetHttp3Error> = serde_json::from_str(&local_var_content).ok();
254        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
255        Err(Error::ResponseError(local_var_error))
256    }
257}
258