Skip to content

Commit

Permalink
Add example and a bit of documentation for new client configurations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Mariette committed Mar 26, 2024
1 parent bb59ab3 commit a42703e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion examples/client_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ fn main() {
let client_config = GraphClientConfiguration::new()
.access_token(ACCESS_TOKEN)
.timeout(Duration::from_secs(30))
.default_headers(HeaderMap::default());
.default_headers(HeaderMap::default())
.retry(Some(10))// retry 10 times if the request is not successful
.concurrency_limit(Some(10))// limit the number of concurrent requests on this client to 10
.wait_for_retry_after_headers(true); // wait the amount of seconds specified by the Retry-After header of the response when we reach the throttling limits (429 Too Many Requests)

let _ = Graph::from(client_config);
}
16 changes: 16 additions & 0 deletions graph-http/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,22 @@ impl GraphClientConfiguration {
self
}

/// Enable a request retry in case of failure and how many times we should retry before giving up
///
/// Some requests may fail on GraphAPI side and should be retried. Only server errors (HTTP code between 500 and 599) with be retried.
///
/// Default is no retry
pub fn retry(mut self, retry: Option<usize>) -> GraphClientConfiguration {
self.config.service_layers_configuration.retry = retry;
self
}

/// Enable a request retry if we reach the throttling limits and GraphAPI returns a 429 Too Many Requests with a Retry-After header
///
/// Be careful with this parameter as some API endpoints have quite low limits (reports for example) and the request may hang for hundreds of seconds.
/// For maximum throughput you may want to not respect the Retry-After header as hitting another server thanks to load-balancing may lead to a successful response.
///
/// Default is no retry
pub fn wait_for_retry_after_headers(mut self, retry: bool) -> GraphClientConfiguration {
self.config
.service_layers_configuration
Expand All @@ -169,6 +180,11 @@ impl GraphClientConfiguration {
self
}

/// Enable a concurrency limit on the client
///
/// Every request through this client will be subject to a concurrency limit. Can be useful to stay under the API limits set by GraphAPI
///
/// Default is no concurrency limit
pub fn concurrency_limit(
mut self,
concurrency_limit: Option<usize>,
Expand Down

0 comments on commit a42703e

Please sign in to comment.