fastly_api/apis/
purge_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 [`bulk_purge_tag`]
15#[derive(Clone, Debug, Default)]
16pub struct BulkPurgeTagParams {
17    /// Alphanumeric string identifying the service.
18    pub service_id: String,
19    /// If present, this header triggers the purge to be 'soft', which marks the affected object as stale rather than making it inaccessible.  Typically set to \"1\" when used, but the value is not important.
20    pub fastly_soft_purge: Option<i32>,
21    /// Purge multiple surrogate key tags using a request header. Not required if a JSON POST body is specified.
22    pub surrogate_key: Option<String>,
23    pub purge_response: Option<crate::models::PurgeResponse>
24}
25
26/// struct for passing parameters to the method [`purge_all`]
27#[derive(Clone, Debug, Default)]
28pub struct PurgeAllParams {
29    /// Alphanumeric string identifying the service.
30    pub service_id: String
31}
32
33/// struct for passing parameters to the method [`purge_single_url`]
34#[derive(Clone, Debug, Default)]
35pub struct PurgeSingleUrlParams {
36    /// URL of object in cache to be purged.
37    pub cached_url: String,
38    /// If present, this header triggers the purge to be 'soft', which marks the affected object as stale rather than making it inaccessible.  Typically set to \"1\" when used, but the value is not important.
39    pub fastly_soft_purge: Option<i32>
40}
41
42/// struct for passing parameters to the method [`purge_tag`]
43#[derive(Clone, Debug, Default)]
44pub struct PurgeTagParams {
45    /// Alphanumeric string identifying the service.
46    pub service_id: String,
47    /// Surrogate keys are used to efficiently purge content from cache. Instead of purging your entire site or individual URLs, you can tag related assets (like all images and descriptions associated with a single product) with surrogate keys, and these grouped URLs can be purged in a single request.
48    pub surrogate_key: String,
49    /// If present, this header triggers the purge to be 'soft', which marks the affected object as stale rather than making it inaccessible.  Typically set to \"1\" when used, but the value is not important.
50    pub fastly_soft_purge: Option<i32>
51}
52
53
54/// struct for typed errors of method [`bulk_purge_tag`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum BulkPurgeTagError {
58    UnknownValue(serde_json::Value),
59}
60
61/// struct for typed errors of method [`purge_all`]
62#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum PurgeAllError {
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`purge_single_url`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum PurgeSingleUrlError {
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`purge_tag`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum PurgeTagError {
79    UnknownValue(serde_json::Value),
80}
81
82
83/// Instant Purge a particular service of items tagged with surrogate keys. Up to 256 surrogate keys can be purged in one batch request. As an alternative to sending the keys in a JSON object in the body of the request, this endpoint also supports listing keys in a <code>Surrogate-Key</code> request header, e.g. <code>Surrogate-Key: key_1 key_2 key_3</code>. 
84pub async fn bulk_purge_tag(configuration: &mut configuration::Configuration, params: BulkPurgeTagParams) -> Result<::std::collections::HashMap<String, String>, Error<BulkPurgeTagError>> {
85    let local_var_configuration = configuration;
86
87    // unbox the parameters
88    let service_id = params.service_id;
89    let fastly_soft_purge = params.fastly_soft_purge;
90    let surrogate_key = params.surrogate_key;
91    let purge_response = params.purge_response;
92
93
94    let local_var_client = &local_var_configuration.client;
95
96    let local_var_uri_str = format!("{}/service/{service_id}/purge", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
97    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
101    }
102    if let Some(local_var_param_value) = fastly_soft_purge {
103        local_var_req_builder = local_var_req_builder.header("fastly-soft-purge", local_var_param_value.to_string());
104    }
105    if let Some(local_var_param_value) = surrogate_key {
106        local_var_req_builder = local_var_req_builder.header("surrogate-key", local_var_param_value.to_string());
107    }
108    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
109        let local_var_key = local_var_apikey.key.clone();
110        let local_var_value = match local_var_apikey.prefix {
111            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
112            None => local_var_key,
113        };
114        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
115    };
116    local_var_req_builder = local_var_req_builder.json(&purge_response);
117
118    let local_var_req = local_var_req_builder.build()?;
119    let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121    if "POST" != "GET" && "POST" != "HEAD" {
122      let headers = local_var_resp.headers();
123      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
124          Some(v) => v.to_str().unwrap().parse().unwrap(),
125          None => configuration::DEFAULT_RATELIMIT,
126      };
127      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
128          Some(v) => v.to_str().unwrap().parse().unwrap(),
129          None => 0,
130      };
131    }
132
133    let local_var_status = local_var_resp.status();
134    let local_var_content = local_var_resp.text().await?;
135
136    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137        serde_json::from_str(&local_var_content).map_err(Error::from)
138    } else {
139        let local_var_entity: Option<BulkPurgeTagError> = serde_json::from_str(&local_var_content).ok();
140        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141        Err(Error::ResponseError(local_var_error))
142    }
143}
144
145/// Instant Purge everything from a service.  Purge-all requests cannot be done in soft mode and will always immediately invalidate all cached content associated with the service. To do a soft-purge-all, consider applying a constant [surrogate key](https://docs.fastly.com/en/guides/getting-started-with-surrogate-keys) tag (e.g., `\"all\"`) to all objects. 
146pub async fn purge_all(configuration: &mut configuration::Configuration, params: PurgeAllParams) -> Result<crate::models::InlineResponse200, Error<PurgeAllError>> {
147    let local_var_configuration = configuration;
148
149    // unbox the parameters
150    let service_id = params.service_id;
151
152
153    let local_var_client = &local_var_configuration.client;
154
155    let local_var_uri_str = format!("{}/service/{service_id}/purge_all", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id));
156    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
157
158    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
159        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
160    }
161    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
162        let local_var_key = local_var_apikey.key.clone();
163        let local_var_value = match local_var_apikey.prefix {
164            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
165            None => local_var_key,
166        };
167        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
168    };
169
170    let local_var_req = local_var_req_builder.build()?;
171    let local_var_resp = local_var_client.execute(local_var_req).await?;
172
173    if "POST" != "GET" && "POST" != "HEAD" {
174      let headers = local_var_resp.headers();
175      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
176          Some(v) => v.to_str().unwrap().parse().unwrap(),
177          None => configuration::DEFAULT_RATELIMIT,
178      };
179      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
180          Some(v) => v.to_str().unwrap().parse().unwrap(),
181          None => 0,
182      };
183    }
184
185    let local_var_status = local_var_resp.status();
186    let local_var_content = local_var_resp.text().await?;
187
188    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
189        serde_json::from_str(&local_var_content).map_err(Error::from)
190    } else {
191        let local_var_entity: Option<PurgeAllError> = serde_json::from_str(&local_var_content).ok();
192        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
193        Err(Error::ResponseError(local_var_error))
194    }
195}
196
197/// Instant Purge an individual URL.
198pub async fn purge_single_url(configuration: &mut configuration::Configuration, params: PurgeSingleUrlParams) -> Result<crate::models::PurgeResponse, Error<PurgeSingleUrlError>> {
199    let local_var_configuration = configuration;
200
201    // unbox the parameters
202    let cached_url = params.cached_url;
203    let fastly_soft_purge = params.fastly_soft_purge;
204
205
206    let local_var_client = &local_var_configuration.client;
207
208    let local_var_uri_str = format!("{}/purge/{cached_url}", local_var_configuration.base_path, cached_url=cached_url);
209    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
210
211    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
212        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
213    }
214    if let Some(local_var_param_value) = fastly_soft_purge {
215        local_var_req_builder = local_var_req_builder.header("fastly-soft-purge", local_var_param_value.to_string());
216    }
217    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
218        let local_var_key = local_var_apikey.key.clone();
219        let local_var_value = match local_var_apikey.prefix {
220            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
221            None => local_var_key,
222        };
223        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
224    };
225
226    let local_var_req = local_var_req_builder.build()?;
227    let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229    if "POST" != "GET" && "POST" != "HEAD" {
230      let headers = local_var_resp.headers();
231      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
232          Some(v) => v.to_str().unwrap().parse().unwrap(),
233          None => configuration::DEFAULT_RATELIMIT,
234      };
235      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
236          Some(v) => v.to_str().unwrap().parse().unwrap(),
237          None => 0,
238      };
239    }
240
241    let local_var_status = local_var_resp.status();
242    let local_var_content = local_var_resp.text().await?;
243
244    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
245        serde_json::from_str(&local_var_content).map_err(Error::from)
246    } else {
247        let local_var_entity: Option<PurgeSingleUrlError> = serde_json::from_str(&local_var_content).ok();
248        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
249        Err(Error::ResponseError(local_var_error))
250    }
251}
252
253/// Instant Purge a particular service of items tagged with a Surrogate Key. Only one surrogate key can be purged at a time. Multiple keys can be purged using a batch surrogate key purge request.
254pub async fn purge_tag(configuration: &mut configuration::Configuration, params: PurgeTagParams) -> Result<crate::models::PurgeResponse, Error<PurgeTagError>> {
255    let local_var_configuration = configuration;
256
257    // unbox the parameters
258    let service_id = params.service_id;
259    let surrogate_key = params.surrogate_key;
260    let fastly_soft_purge = params.fastly_soft_purge;
261
262
263    let local_var_client = &local_var_configuration.client;
264
265    let local_var_uri_str = format!("{}/service/{service_id}/purge/{surrogate_key}", local_var_configuration.base_path, service_id=crate::apis::urlencode(service_id), surrogate_key=surrogate_key);
266    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
267
268    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
269        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
270    }
271    if let Some(local_var_param_value) = fastly_soft_purge {
272        local_var_req_builder = local_var_req_builder.header("fastly-soft-purge", local_var_param_value.to_string());
273    }
274    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
275        let local_var_key = local_var_apikey.key.clone();
276        let local_var_value = match local_var_apikey.prefix {
277            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
278            None => local_var_key,
279        };
280        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
281    };
282
283    let local_var_req = local_var_req_builder.build()?;
284    let local_var_resp = local_var_client.execute(local_var_req).await?;
285
286    if "POST" != "GET" && "POST" != "HEAD" {
287      let headers = local_var_resp.headers();
288      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
289          Some(v) => v.to_str().unwrap().parse().unwrap(),
290          None => configuration::DEFAULT_RATELIMIT,
291      };
292      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
293          Some(v) => v.to_str().unwrap().parse().unwrap(),
294          None => 0,
295      };
296    }
297
298    let local_var_status = local_var_resp.status();
299    let local_var_content = local_var_resp.text().await?;
300
301    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
302        serde_json::from_str(&local_var_content).map_err(Error::from)
303    } else {
304        let local_var_entity: Option<PurgeTagError> = serde_json::from_str(&local_var_content).ok();
305        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
306        Err(Error::ResponseError(local_var_error))
307    }
308}
309