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