Skip to main content

fastly_api/apis/
backend_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_backend`]
15#[derive(Clone, Debug, Default)]
16pub struct CreateBackendParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// Integer identifying a service version.
20    pub version_id: i32,
21    /// A hostname, IPv4, or IPv6 address for the backend. This is the preferred way to specify the location of your backend.
22    pub address: Option<String>,
23    /// Whether or not this backend should be automatically load balanced. If true, all backends with this setting that don't have a `request_condition` will be selected based on their `weight`.
24    pub auto_loadbalance: Option<bool>,
25    /// Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. If exceeded, for Delivery services, the response received so far will be considered complete and the fetch will end. For Compute services, timeout expiration is treated as a failure of the backend connection, and an error is generated. May be set at runtime using `bereq.between_bytes_timeout`.
26    pub between_bytes_timeout: Option<i32>,
27    /// Unused.
28    pub client_cert: Option<String>,
29    /// A freeform descriptive note.
30    pub comment: Option<String>,
31    /// Maximum duration in milliseconds to wait for a connection to this backend to be established. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.connect_timeout`.
32    pub connect_timeout: Option<i32>,
33    /// Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.first_byte_timeout`.
34    pub first_byte_timeout: Option<i32>,
35    /// Maximum duration in milliseconds to wait for the entire response to be received after a TCP connection is established and the request has been sent. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.fetch_timeout`.
36    pub fetch_timeout: Option<i32>,
37    /// The name of the healthcheck to use with this backend.
38    pub healthcheck: Option<String>,
39    /// The hostname of the backend. May be used as an alternative to `address` to set the backend location.
40    pub hostname: Option<String>,
41    /// IPv4 address of the backend. May be used as an alternative to `address` to set the backend location.
42    pub ipv4: Option<String>,
43    /// IPv6 address of the backend. May be used as an alternative to `address` to set the backend location.
44    pub ipv6: Option<String>,
45    /// How long in seconds to keep a persistent connection to the backend between requests. By default, Varnish keeps connections open as long as it can.
46    pub keepalive_time: Option<i32>,
47    /// Maximum number of concurrent connections this backend will accept.
48    pub max_conn: Option<i32>,
49    /// Maximum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
50    pub max_tls_version: Option<String>,
51    /// Minimum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
52    pub min_tls_version: Option<String>,
53    /// The name of the backend.
54    pub name: Option<String>,
55    /// If set, will replace the client-supplied HTTP `Host` header on connections to this backend. Applied after VCL has been processed, so this setting will take precedence over changing `bereq.http.Host` in VCL.
56    pub override_host: Option<String>,
57    /// Port on which the backend server is listening for connections from Fastly. Setting `port` to 80 or 443 will also set `use_ssl` automatically (to false and true respectively), unless explicitly overridden by setting `use_ssl` in the same request.
58    pub port: Option<i32>,
59    /// Prefer IPv6 connections to origins for hostname backends. Default is 'false' for Delivery services and 'true' for Compute services.
60    pub prefer_ipv6: Option<bool>,
61    /// Name of a Condition, which if satisfied, will select this backend during a request. If set, will override any `auto_loadbalance` setting. By default, the first backend added to a service is selected for all requests.
62    pub request_condition: Option<String>,
63    /// Value that when shared across backends will enable those backends to share the same health check.
64    pub share_key: Option<String>,
65    /// Identifier of the POP to use as a [shield](https://www.fastly.com/documentation/guides/getting-started/hosts/shielding/).
66    pub shield: Option<String>,
67    /// CA certificate attached to origin.
68    pub ssl_ca_cert: Option<String>,
69    /// Overrides `ssl_hostname`, but only for cert verification. Does not affect SNI at all.
70    pub ssl_cert_hostname: Option<String>,
71    /// Be strict on checking SSL certs.
72    pub ssl_check_cert: Option<bool>,
73    /// List of [OpenSSL ciphers](https://www.openssl.org/docs/man1.1.1/man1/ciphers.html) to support for connections to this origin. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
74    pub ssl_ciphers: Option<String>,
75    /// Client certificate attached to origin.
76    pub ssl_client_cert: Option<String>,
77    /// Client key attached to origin.
78    pub ssl_client_key: Option<String>,
79    /// Use `ssl_cert_hostname` and `ssl_sni_hostname` to configure certificate validation.
80    pub ssl_hostname: Option<String>,
81    /// Overrides `ssl_hostname`, but only for SNI in the handshake. Does not affect cert validation at all.
82    pub ssl_sni_hostname: Option<String>,
83    /// Whether to enable TCP keepalives for backend connections. Varnish defaults to using keepalives if this is unspecified.
84    pub tcp_keepalive_enable: Option<bool>,
85    /// Interval in seconds between subsequent keepalive probes.
86    pub tcp_keepalive_interval: Option<i32>,
87    /// Number of unacknowledged probes to send before considering the connection dead.
88    pub tcp_keepalive_probes: Option<i32>,
89    /// Interval in seconds between the last data packet sent and the first keepalive probe.
90    pub tcp_keepalive_time: Option<i32>,
91    /// Whether or not to require TLS for connections to this backend.
92    pub use_ssl: Option<bool>,
93    /// Weight used to load balance this backend against others. May be any positive integer. If `auto_loadbalance` is true, the chance of this backend being selected is equal to its own weight over the sum of all weights for backends that have `auto_loadbalance` set to true.
94    pub weight: Option<i32>
95}
96
97/// struct for passing parameters to the method [`delete_backend`]
98#[derive(Clone, Debug, Default)]
99pub struct DeleteBackendParams {
100    /// Alphanumeric string identifying the service.
101    pub service_id: String,
102    /// Integer identifying a service version.
103    pub version_id: i32,
104    /// The name of the backend.
105    pub backend_name: String
106}
107
108/// struct for passing parameters to the method [`get_backend`]
109#[derive(Clone, Debug, Default)]
110pub struct GetBackendParams {
111    /// Alphanumeric string identifying the service.
112    pub service_id: String,
113    /// Integer identifying a service version.
114    pub version_id: i32,
115    /// The name of the backend.
116    pub backend_name: String
117}
118
119/// struct for passing parameters to the method [`list_backends`]
120#[derive(Clone, Debug, Default)]
121pub struct ListBackendsParams {
122    /// Alphanumeric string identifying the service.
123    pub service_id: String,
124    /// Integer identifying a service version.
125    pub version_id: i32
126}
127
128/// struct for passing parameters to the method [`update_backend`]
129#[derive(Clone, Debug, Default)]
130pub struct UpdateBackendParams {
131    /// Alphanumeric string identifying the service.
132    pub service_id: String,
133    /// Integer identifying a service version.
134    pub version_id: i32,
135    /// The name of the backend.
136    pub backend_name: String,
137    /// A hostname, IPv4, or IPv6 address for the backend. This is the preferred way to specify the location of your backend.
138    pub address: Option<String>,
139    /// Whether or not this backend should be automatically load balanced. If true, all backends with this setting that don't have a `request_condition` will be selected based on their `weight`.
140    pub auto_loadbalance: Option<bool>,
141    /// Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. If exceeded, for Delivery services, the response received so far will be considered complete and the fetch will end. For Compute services, timeout expiration is treated as a failure of the backend connection, and an error is generated. May be set at runtime using `bereq.between_bytes_timeout`.
142    pub between_bytes_timeout: Option<i32>,
143    /// Unused.
144    pub client_cert: Option<String>,
145    /// A freeform descriptive note.
146    pub comment: Option<String>,
147    /// Maximum duration in milliseconds to wait for a connection to this backend to be established. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.connect_timeout`.
148    pub connect_timeout: Option<i32>,
149    /// Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.first_byte_timeout`.
150    pub first_byte_timeout: Option<i32>,
151    /// Maximum duration in milliseconds to wait for the entire response to be received after a TCP connection is established and the request has been sent. If exceeded, the connection is aborted and a synthetic `503` response will be presented instead. May be set at runtime using `bereq.fetch_timeout`.
152    pub fetch_timeout: Option<i32>,
153    /// The name of the healthcheck to use with this backend.
154    pub healthcheck: Option<String>,
155    /// The hostname of the backend. May be used as an alternative to `address` to set the backend location.
156    pub hostname: Option<String>,
157    /// IPv4 address of the backend. May be used as an alternative to `address` to set the backend location.
158    pub ipv4: Option<String>,
159    /// IPv6 address of the backend. May be used as an alternative to `address` to set the backend location.
160    pub ipv6: Option<String>,
161    /// How long in seconds to keep a persistent connection to the backend between requests. By default, Varnish keeps connections open as long as it can.
162    pub keepalive_time: Option<i32>,
163    /// Maximum number of concurrent connections this backend will accept.
164    pub max_conn: Option<i32>,
165    /// Maximum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
166    pub max_tls_version: Option<String>,
167    /// Minimum allowed TLS version on SSL connections to this backend. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
168    pub min_tls_version: Option<String>,
169    /// The name of the backend.
170    pub name: Option<String>,
171    /// If set, will replace the client-supplied HTTP `Host` header on connections to this backend. Applied after VCL has been processed, so this setting will take precedence over changing `bereq.http.Host` in VCL.
172    pub override_host: Option<String>,
173    /// Port on which the backend server is listening for connections from Fastly. Setting `port` to 80 or 443 will also set `use_ssl` automatically (to false and true respectively), unless explicitly overridden by setting `use_ssl` in the same request.
174    pub port: Option<i32>,
175    /// Prefer IPv6 connections to origins for hostname backends. Default is 'false' for Delivery services and 'true' for Compute services.
176    pub prefer_ipv6: Option<bool>,
177    /// Name of a Condition, which if satisfied, will select this backend during a request. If set, will override any `auto_loadbalance` setting. By default, the first backend added to a service is selected for all requests.
178    pub request_condition: Option<String>,
179    /// Value that when shared across backends will enable those backends to share the same health check.
180    pub share_key: Option<String>,
181    /// Identifier of the POP to use as a [shield](https://www.fastly.com/documentation/guides/getting-started/hosts/shielding/).
182    pub shield: Option<String>,
183    /// CA certificate attached to origin.
184    pub ssl_ca_cert: Option<String>,
185    /// Overrides `ssl_hostname`, but only for cert verification. Does not affect SNI at all.
186    pub ssl_cert_hostname: Option<String>,
187    /// Be strict on checking SSL certs.
188    pub ssl_check_cert: Option<bool>,
189    /// List of [OpenSSL ciphers](https://www.openssl.org/docs/man1.1.1/man1/ciphers.html) to support for connections to this origin. If your backend server is not able to negotiate a connection meeting this constraint, a synthetic `503` error response will be generated.
190    pub ssl_ciphers: Option<String>,
191    /// Client certificate attached to origin.
192    pub ssl_client_cert: Option<String>,
193    /// Client key attached to origin.
194    pub ssl_client_key: Option<String>,
195    /// Use `ssl_cert_hostname` and `ssl_sni_hostname` to configure certificate validation.
196    pub ssl_hostname: Option<String>,
197    /// Overrides `ssl_hostname`, but only for SNI in the handshake. Does not affect cert validation at all.
198    pub ssl_sni_hostname: Option<String>,
199    /// Whether to enable TCP keepalives for backend connections. Varnish defaults to using keepalives if this is unspecified.
200    pub tcp_keepalive_enable: Option<bool>,
201    /// Interval in seconds between subsequent keepalive probes.
202    pub tcp_keepalive_interval: Option<i32>,
203    /// Number of unacknowledged probes to send before considering the connection dead.
204    pub tcp_keepalive_probes: Option<i32>,
205    /// Interval in seconds between the last data packet sent and the first keepalive probe.
206    pub tcp_keepalive_time: Option<i32>,
207    /// Whether or not to require TLS for connections to this backend.
208    pub use_ssl: Option<bool>,
209    /// Weight used to load balance this backend against others. May be any positive integer. If `auto_loadbalance` is true, the chance of this backend being selected is equal to its own weight over the sum of all weights for backends that have `auto_loadbalance` set to true.
210    pub weight: Option<i32>
211}
212
213
214/// struct for typed errors of method [`create_backend`]
215#[derive(Debug, Clone, Serialize, Deserialize)]
216#[serde(untagged)]
217pub enum CreateBackendError {
218    UnknownValue(serde_json::Value),
219}
220
221/// struct for typed errors of method [`delete_backend`]
222#[derive(Debug, Clone, Serialize, Deserialize)]
223#[serde(untagged)]
224pub enum DeleteBackendError {
225    UnknownValue(serde_json::Value),
226}
227
228/// struct for typed errors of method [`get_backend`]
229#[derive(Debug, Clone, Serialize, Deserialize)]
230#[serde(untagged)]
231pub enum GetBackendError {
232    UnknownValue(serde_json::Value),
233}
234
235/// struct for typed errors of method [`list_backends`]
236#[derive(Debug, Clone, Serialize, Deserialize)]
237#[serde(untagged)]
238pub enum ListBackendsError {
239    UnknownValue(serde_json::Value),
240}
241
242/// struct for typed errors of method [`update_backend`]
243#[derive(Debug, Clone, Serialize, Deserialize)]
244#[serde(untagged)]
245pub enum UpdateBackendError {
246    UnknownValue(serde_json::Value),
247}
248
249
250/// Create a backend for a particular service and version.
251pub async fn create_backend(configuration: &mut configuration::Configuration, params: CreateBackendParams) -> Result<crate::models::BackendResponse, Error<CreateBackendError>> {
252    let local_var_configuration = configuration;
253
254    // unbox the parameters
255    let service_id = params.service_id;
256    let version_id = params.version_id;
257    let address = params.address;
258    let auto_loadbalance = params.auto_loadbalance;
259    let between_bytes_timeout = params.between_bytes_timeout;
260    let client_cert = params.client_cert;
261    let comment = params.comment;
262    let connect_timeout = params.connect_timeout;
263    let first_byte_timeout = params.first_byte_timeout;
264    let fetch_timeout = params.fetch_timeout;
265    let healthcheck = params.healthcheck;
266    let hostname = params.hostname;
267    let ipv4 = params.ipv4;
268    let ipv6 = params.ipv6;
269    let keepalive_time = params.keepalive_time;
270    let max_conn = params.max_conn;
271    let max_tls_version = params.max_tls_version;
272    let min_tls_version = params.min_tls_version;
273    let name = params.name;
274    let override_host = params.override_host;
275    let port = params.port;
276    let prefer_ipv6 = params.prefer_ipv6;
277    let request_condition = params.request_condition;
278    let share_key = params.share_key;
279    let shield = params.shield;
280    let ssl_ca_cert = params.ssl_ca_cert;
281    let ssl_cert_hostname = params.ssl_cert_hostname;
282    let ssl_check_cert = params.ssl_check_cert;
283    let ssl_ciphers = params.ssl_ciphers;
284    let ssl_client_cert = params.ssl_client_cert;
285    let ssl_client_key = params.ssl_client_key;
286    let ssl_hostname = params.ssl_hostname;
287    let ssl_sni_hostname = params.ssl_sni_hostname;
288    let tcp_keepalive_enable = params.tcp_keepalive_enable;
289    let tcp_keepalive_interval = params.tcp_keepalive_interval;
290    let tcp_keepalive_probes = params.tcp_keepalive_probes;
291    let tcp_keepalive_time = params.tcp_keepalive_time;
292    let use_ssl = params.use_ssl;
293    let weight = params.weight;
294
295
296    let local_var_client = &local_var_configuration.client;
297
298    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
299    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
300
301    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
302        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
303    }
304    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
305        let local_var_key = local_var_apikey.key.clone();
306        let local_var_value = match local_var_apikey.prefix {
307            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
308            None => local_var_key,
309        };
310        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
311    };
312    let mut local_var_form_params = std::collections::HashMap::new();
313    if let Some(local_var_param_value) = address {
314        local_var_form_params.insert("address", local_var_param_value.to_string());
315    }
316    if let Some(local_var_param_value) = auto_loadbalance {
317        local_var_form_params.insert("auto_loadbalance", local_var_param_value.to_string());
318    }
319    if let Some(local_var_param_value) = between_bytes_timeout {
320        local_var_form_params.insert("between_bytes_timeout", local_var_param_value.to_string());
321    }
322    if let Some(local_var_param_value) = client_cert {
323        local_var_form_params.insert("client_cert", local_var_param_value.to_string());
324    }
325    if let Some(local_var_param_value) = comment {
326        local_var_form_params.insert("comment", local_var_param_value.to_string());
327    }
328    if let Some(local_var_param_value) = connect_timeout {
329        local_var_form_params.insert("connect_timeout", local_var_param_value.to_string());
330    }
331    if let Some(local_var_param_value) = first_byte_timeout {
332        local_var_form_params.insert("first_byte_timeout", local_var_param_value.to_string());
333    }
334    if let Some(local_var_param_value) = fetch_timeout {
335        local_var_form_params.insert("fetch_timeout", local_var_param_value.to_string());
336    }
337    if let Some(local_var_param_value) = healthcheck {
338        local_var_form_params.insert("healthcheck", local_var_param_value.to_string());
339    }
340    if let Some(local_var_param_value) = hostname {
341        local_var_form_params.insert("hostname", local_var_param_value.to_string());
342    }
343    if let Some(local_var_param_value) = ipv4 {
344        local_var_form_params.insert("ipv4", local_var_param_value.to_string());
345    }
346    if let Some(local_var_param_value) = ipv6 {
347        local_var_form_params.insert("ipv6", local_var_param_value.to_string());
348    }
349    if let Some(local_var_param_value) = keepalive_time {
350        local_var_form_params.insert("keepalive_time", local_var_param_value.to_string());
351    }
352    if let Some(local_var_param_value) = max_conn {
353        local_var_form_params.insert("max_conn", local_var_param_value.to_string());
354    }
355    if let Some(local_var_param_value) = max_tls_version {
356        local_var_form_params.insert("max_tls_version", local_var_param_value.to_string());
357    }
358    if let Some(local_var_param_value) = min_tls_version {
359        local_var_form_params.insert("min_tls_version", local_var_param_value.to_string());
360    }
361    if let Some(local_var_param_value) = name {
362        local_var_form_params.insert("name", local_var_param_value.to_string());
363    }
364    if let Some(local_var_param_value) = override_host {
365        local_var_form_params.insert("override_host", local_var_param_value.to_string());
366    }
367    if let Some(local_var_param_value) = port {
368        local_var_form_params.insert("port", local_var_param_value.to_string());
369    }
370    if let Some(local_var_param_value) = prefer_ipv6 {
371        local_var_form_params.insert("prefer_ipv6", local_var_param_value.to_string());
372    }
373    if let Some(local_var_param_value) = request_condition {
374        local_var_form_params.insert("request_condition", local_var_param_value.to_string());
375    }
376    if let Some(local_var_param_value) = share_key {
377        local_var_form_params.insert("share_key", local_var_param_value.to_string());
378    }
379    if let Some(local_var_param_value) = shield {
380        local_var_form_params.insert("shield", local_var_param_value.to_string());
381    }
382    if let Some(local_var_param_value) = ssl_ca_cert {
383        local_var_form_params.insert("ssl_ca_cert", local_var_param_value.to_string());
384    }
385    if let Some(local_var_param_value) = ssl_cert_hostname {
386        local_var_form_params.insert("ssl_cert_hostname", local_var_param_value.to_string());
387    }
388    if let Some(local_var_param_value) = ssl_check_cert {
389        local_var_form_params.insert("ssl_check_cert", local_var_param_value.to_string());
390    }
391    if let Some(local_var_param_value) = ssl_ciphers {
392        local_var_form_params.insert("ssl_ciphers", local_var_param_value.to_string());
393    }
394    if let Some(local_var_param_value) = ssl_client_cert {
395        local_var_form_params.insert("ssl_client_cert", local_var_param_value.to_string());
396    }
397    if let Some(local_var_param_value) = ssl_client_key {
398        local_var_form_params.insert("ssl_client_key", local_var_param_value.to_string());
399    }
400    if let Some(local_var_param_value) = ssl_hostname {
401        local_var_form_params.insert("ssl_hostname", local_var_param_value.to_string());
402    }
403    if let Some(local_var_param_value) = ssl_sni_hostname {
404        local_var_form_params.insert("ssl_sni_hostname", local_var_param_value.to_string());
405    }
406    if let Some(local_var_param_value) = tcp_keepalive_enable {
407        local_var_form_params.insert("tcp_keepalive_enable", local_var_param_value.to_string());
408    }
409    if let Some(local_var_param_value) = tcp_keepalive_interval {
410        local_var_form_params.insert("tcp_keepalive_interval", local_var_param_value.to_string());
411    }
412    if let Some(local_var_param_value) = tcp_keepalive_probes {
413        local_var_form_params.insert("tcp_keepalive_probes", local_var_param_value.to_string());
414    }
415    if let Some(local_var_param_value) = tcp_keepalive_time {
416        local_var_form_params.insert("tcp_keepalive_time", local_var_param_value.to_string());
417    }
418    if let Some(local_var_param_value) = use_ssl {
419        local_var_form_params.insert("use_ssl", local_var_param_value.to_string());
420    }
421    if let Some(local_var_param_value) = weight {
422        local_var_form_params.insert("weight", local_var_param_value.to_string());
423    }
424    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
425
426    let local_var_req = local_var_req_builder.build()?;
427    let local_var_resp = local_var_client.execute(local_var_req).await?;
428
429    if "POST" != "GET" && "POST" != "HEAD" {
430      let headers = local_var_resp.headers();
431      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
432          Some(v) => v.to_str().unwrap().parse().unwrap(),
433          None => configuration::DEFAULT_RATELIMIT,
434      };
435      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
436          Some(v) => v.to_str().unwrap().parse().unwrap(),
437          None => 0,
438      };
439    }
440
441    let local_var_status = local_var_resp.status();
442    let local_var_content = local_var_resp.text().await?;
443
444    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
445        serde_json::from_str(&local_var_content).map_err(Error::from)
446    } else {
447        let local_var_entity: Option<CreateBackendError> = serde_json::from_str(&local_var_content).ok();
448        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
449        Err(Error::ResponseError(local_var_error))
450    }
451}
452
453/// Delete the backend for a particular service and version.
454pub async fn delete_backend(configuration: &mut configuration::Configuration, params: DeleteBackendParams) -> Result<crate::models::InlineResponse200, Error<DeleteBackendError>> {
455    let local_var_configuration = configuration;
456
457    // unbox the parameters
458    let service_id = params.service_id;
459    let version_id = params.version_id;
460    let backend_name = params.backend_name;
461
462
463    let local_var_client = &local_var_configuration.client;
464
465    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend/{backend_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
466    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
467
468    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
469        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
470    }
471    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
472        let local_var_key = local_var_apikey.key.clone();
473        let local_var_value = match local_var_apikey.prefix {
474            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
475            None => local_var_key,
476        };
477        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
478    };
479
480    let local_var_req = local_var_req_builder.build()?;
481    let local_var_resp = local_var_client.execute(local_var_req).await?;
482
483    if "DELETE" != "GET" && "DELETE" != "HEAD" {
484      let headers = local_var_resp.headers();
485      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
486          Some(v) => v.to_str().unwrap().parse().unwrap(),
487          None => configuration::DEFAULT_RATELIMIT,
488      };
489      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
490          Some(v) => v.to_str().unwrap().parse().unwrap(),
491          None => 0,
492      };
493    }
494
495    let local_var_status = local_var_resp.status();
496    let local_var_content = local_var_resp.text().await?;
497
498    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
499        serde_json::from_str(&local_var_content).map_err(Error::from)
500    } else {
501        let local_var_entity: Option<DeleteBackendError> = serde_json::from_str(&local_var_content).ok();
502        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
503        Err(Error::ResponseError(local_var_error))
504    }
505}
506
507/// Get the backend for a particular service and version.
508pub async fn get_backend(configuration: &mut configuration::Configuration, params: GetBackendParams) -> Result<crate::models::BackendResponse, Error<GetBackendError>> {
509    let local_var_configuration = configuration;
510
511    // unbox the parameters
512    let service_id = params.service_id;
513    let version_id = params.version_id;
514    let backend_name = params.backend_name;
515
516
517    let local_var_client = &local_var_configuration.client;
518
519    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend/{backend_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
520    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
521
522    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
523        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
524    }
525    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
526        let local_var_key = local_var_apikey.key.clone();
527        let local_var_value = match local_var_apikey.prefix {
528            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
529            None => local_var_key,
530        };
531        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
532    };
533
534    let local_var_req = local_var_req_builder.build()?;
535    let local_var_resp = local_var_client.execute(local_var_req).await?;
536
537    if "GET" != "GET" && "GET" != "HEAD" {
538      let headers = local_var_resp.headers();
539      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
540          Some(v) => v.to_str().unwrap().parse().unwrap(),
541          None => configuration::DEFAULT_RATELIMIT,
542      };
543      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
544          Some(v) => v.to_str().unwrap().parse().unwrap(),
545          None => 0,
546      };
547    }
548
549    let local_var_status = local_var_resp.status();
550    let local_var_content = local_var_resp.text().await?;
551
552    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
553        serde_json::from_str(&local_var_content).map_err(Error::from)
554    } else {
555        let local_var_entity: Option<GetBackendError> = serde_json::from_str(&local_var_content).ok();
556        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
557        Err(Error::ResponseError(local_var_error))
558    }
559}
560
561/// List all backends for a particular service and version.
562pub async fn list_backends(configuration: &mut configuration::Configuration, params: ListBackendsParams) -> Result<Vec<crate::models::BackendResponse>, Error<ListBackendsError>> {
563    let local_var_configuration = configuration;
564
565    // unbox the parameters
566    let service_id = params.service_id;
567    let version_id = params.version_id;
568
569
570    let local_var_client = &local_var_configuration.client;
571
572    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id);
573    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
574
575    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
576        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
577    }
578    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
579        let local_var_key = local_var_apikey.key.clone();
580        let local_var_value = match local_var_apikey.prefix {
581            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
582            None => local_var_key,
583        };
584        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
585    };
586
587    let local_var_req = local_var_req_builder.build()?;
588    let local_var_resp = local_var_client.execute(local_var_req).await?;
589
590    if "GET" != "GET" && "GET" != "HEAD" {
591      let headers = local_var_resp.headers();
592      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
593          Some(v) => v.to_str().unwrap().parse().unwrap(),
594          None => configuration::DEFAULT_RATELIMIT,
595      };
596      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
597          Some(v) => v.to_str().unwrap().parse().unwrap(),
598          None => 0,
599      };
600    }
601
602    let local_var_status = local_var_resp.status();
603    let local_var_content = local_var_resp.text().await?;
604
605    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
606        serde_json::from_str(&local_var_content).map_err(Error::from)
607    } else {
608        let local_var_entity: Option<ListBackendsError> = serde_json::from_str(&local_var_content).ok();
609        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
610        Err(Error::ResponseError(local_var_error))
611    }
612}
613
614/// Update the backend for a particular service and version.
615pub async fn update_backend(configuration: &mut configuration::Configuration, params: UpdateBackendParams) -> Result<crate::models::BackendResponse, Error<UpdateBackendError>> {
616    let local_var_configuration = configuration;
617
618    // unbox the parameters
619    let service_id = params.service_id;
620    let version_id = params.version_id;
621    let backend_name = params.backend_name;
622    let address = params.address;
623    let auto_loadbalance = params.auto_loadbalance;
624    let between_bytes_timeout = params.between_bytes_timeout;
625    let client_cert = params.client_cert;
626    let comment = params.comment;
627    let connect_timeout = params.connect_timeout;
628    let first_byte_timeout = params.first_byte_timeout;
629    let fetch_timeout = params.fetch_timeout;
630    let healthcheck = params.healthcheck;
631    let hostname = params.hostname;
632    let ipv4 = params.ipv4;
633    let ipv6 = params.ipv6;
634    let keepalive_time = params.keepalive_time;
635    let max_conn = params.max_conn;
636    let max_tls_version = params.max_tls_version;
637    let min_tls_version = params.min_tls_version;
638    let name = params.name;
639    let override_host = params.override_host;
640    let port = params.port;
641    let prefer_ipv6 = params.prefer_ipv6;
642    let request_condition = params.request_condition;
643    let share_key = params.share_key;
644    let shield = params.shield;
645    let ssl_ca_cert = params.ssl_ca_cert;
646    let ssl_cert_hostname = params.ssl_cert_hostname;
647    let ssl_check_cert = params.ssl_check_cert;
648    let ssl_ciphers = params.ssl_ciphers;
649    let ssl_client_cert = params.ssl_client_cert;
650    let ssl_client_key = params.ssl_client_key;
651    let ssl_hostname = params.ssl_hostname;
652    let ssl_sni_hostname = params.ssl_sni_hostname;
653    let tcp_keepalive_enable = params.tcp_keepalive_enable;
654    let tcp_keepalive_interval = params.tcp_keepalive_interval;
655    let tcp_keepalive_probes = params.tcp_keepalive_probes;
656    let tcp_keepalive_time = params.tcp_keepalive_time;
657    let use_ssl = params.use_ssl;
658    let weight = params.weight;
659
660
661    let local_var_client = &local_var_configuration.client;
662
663    let local_var_uri_str = format!("{}/service/{service_id}/version/{version_id}/backend/{backend_name}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), version_id=version_id, backend_name=crate::apis::urlencode(backend_name));
664    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
665
666    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
667        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
668    }
669    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
670        let local_var_key = local_var_apikey.key.clone();
671        let local_var_value = match local_var_apikey.prefix {
672            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
673            None => local_var_key,
674        };
675        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
676    };
677    let mut local_var_form_params = std::collections::HashMap::new();
678    if let Some(local_var_param_value) = address {
679        local_var_form_params.insert("address", local_var_param_value.to_string());
680    }
681    if let Some(local_var_param_value) = auto_loadbalance {
682        local_var_form_params.insert("auto_loadbalance", local_var_param_value.to_string());
683    }
684    if let Some(local_var_param_value) = between_bytes_timeout {
685        local_var_form_params.insert("between_bytes_timeout", local_var_param_value.to_string());
686    }
687    if let Some(local_var_param_value) = client_cert {
688        local_var_form_params.insert("client_cert", local_var_param_value.to_string());
689    }
690    if let Some(local_var_param_value) = comment {
691        local_var_form_params.insert("comment", local_var_param_value.to_string());
692    }
693    if let Some(local_var_param_value) = connect_timeout {
694        local_var_form_params.insert("connect_timeout", local_var_param_value.to_string());
695    }
696    if let Some(local_var_param_value) = first_byte_timeout {
697        local_var_form_params.insert("first_byte_timeout", local_var_param_value.to_string());
698    }
699    if let Some(local_var_param_value) = fetch_timeout {
700        local_var_form_params.insert("fetch_timeout", local_var_param_value.to_string());
701    }
702    if let Some(local_var_param_value) = healthcheck {
703        local_var_form_params.insert("healthcheck", local_var_param_value.to_string());
704    }
705    if let Some(local_var_param_value) = hostname {
706        local_var_form_params.insert("hostname", local_var_param_value.to_string());
707    }
708    if let Some(local_var_param_value) = ipv4 {
709        local_var_form_params.insert("ipv4", local_var_param_value.to_string());
710    }
711    if let Some(local_var_param_value) = ipv6 {
712        local_var_form_params.insert("ipv6", local_var_param_value.to_string());
713    }
714    if let Some(local_var_param_value) = keepalive_time {
715        local_var_form_params.insert("keepalive_time", local_var_param_value.to_string());
716    }
717    if let Some(local_var_param_value) = max_conn {
718        local_var_form_params.insert("max_conn", local_var_param_value.to_string());
719    }
720    if let Some(local_var_param_value) = max_tls_version {
721        local_var_form_params.insert("max_tls_version", local_var_param_value.to_string());
722    }
723    if let Some(local_var_param_value) = min_tls_version {
724        local_var_form_params.insert("min_tls_version", local_var_param_value.to_string());
725    }
726    if let Some(local_var_param_value) = name {
727        local_var_form_params.insert("name", local_var_param_value.to_string());
728    }
729    if let Some(local_var_param_value) = override_host {
730        local_var_form_params.insert("override_host", local_var_param_value.to_string());
731    }
732    if let Some(local_var_param_value) = port {
733        local_var_form_params.insert("port", local_var_param_value.to_string());
734    }
735    if let Some(local_var_param_value) = prefer_ipv6 {
736        local_var_form_params.insert("prefer_ipv6", local_var_param_value.to_string());
737    }
738    if let Some(local_var_param_value) = request_condition {
739        local_var_form_params.insert("request_condition", local_var_param_value.to_string());
740    }
741    if let Some(local_var_param_value) = share_key {
742        local_var_form_params.insert("share_key", local_var_param_value.to_string());
743    }
744    if let Some(local_var_param_value) = shield {
745        local_var_form_params.insert("shield", local_var_param_value.to_string());
746    }
747    if let Some(local_var_param_value) = ssl_ca_cert {
748        local_var_form_params.insert("ssl_ca_cert", local_var_param_value.to_string());
749    }
750    if let Some(local_var_param_value) = ssl_cert_hostname {
751        local_var_form_params.insert("ssl_cert_hostname", local_var_param_value.to_string());
752    }
753    if let Some(local_var_param_value) = ssl_check_cert {
754        local_var_form_params.insert("ssl_check_cert", local_var_param_value.to_string());
755    }
756    if let Some(local_var_param_value) = ssl_ciphers {
757        local_var_form_params.insert("ssl_ciphers", local_var_param_value.to_string());
758    }
759    if let Some(local_var_param_value) = ssl_client_cert {
760        local_var_form_params.insert("ssl_client_cert", local_var_param_value.to_string());
761    }
762    if let Some(local_var_param_value) = ssl_client_key {
763        local_var_form_params.insert("ssl_client_key", local_var_param_value.to_string());
764    }
765    if let Some(local_var_param_value) = ssl_hostname {
766        local_var_form_params.insert("ssl_hostname", local_var_param_value.to_string());
767    }
768    if let Some(local_var_param_value) = ssl_sni_hostname {
769        local_var_form_params.insert("ssl_sni_hostname", local_var_param_value.to_string());
770    }
771    if let Some(local_var_param_value) = tcp_keepalive_enable {
772        local_var_form_params.insert("tcp_keepalive_enable", local_var_param_value.to_string());
773    }
774    if let Some(local_var_param_value) = tcp_keepalive_interval {
775        local_var_form_params.insert("tcp_keepalive_interval", local_var_param_value.to_string());
776    }
777    if let Some(local_var_param_value) = tcp_keepalive_probes {
778        local_var_form_params.insert("tcp_keepalive_probes", local_var_param_value.to_string());
779    }
780    if let Some(local_var_param_value) = tcp_keepalive_time {
781        local_var_form_params.insert("tcp_keepalive_time", local_var_param_value.to_string());
782    }
783    if let Some(local_var_param_value) = use_ssl {
784        local_var_form_params.insert("use_ssl", local_var_param_value.to_string());
785    }
786    if let Some(local_var_param_value) = weight {
787        local_var_form_params.insert("weight", local_var_param_value.to_string());
788    }
789    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
790
791    let local_var_req = local_var_req_builder.build()?;
792    let local_var_resp = local_var_client.execute(local_var_req).await?;
793
794    if "PUT" != "GET" && "PUT" != "HEAD" {
795      let headers = local_var_resp.headers();
796      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
797          Some(v) => v.to_str().unwrap().parse().unwrap(),
798          None => configuration::DEFAULT_RATELIMIT,
799      };
800      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
801          Some(v) => v.to_str().unwrap().parse().unwrap(),
802          None => 0,
803      };
804    }
805
806    let local_var_status = local_var_resp.status();
807    let local_var_content = local_var_resp.text().await?;
808
809    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
810        serde_json::from_str(&local_var_content).map_err(Error::from)
811    } else {
812        let local_var_entity: Option<UpdateBackendError> = serde_json::from_str(&local_var_content).ok();
813        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
814        Err(Error::ResponseError(local_var_error))
815    }
816}
817