pub struct APIContextOptions { /* private fields */ }Expand description
Options for creating an API request context.
§Example
use viewpoint_core::api::APIContextOptions;
use std::time::Duration;
let options = APIContextOptions::new()
.base_url("https://api.example.com")
.timeout(Duration::from_secs(30))
.extra_http_headers([
("Authorization".to_string(), "Bearer token".to_string()),
]);Implementations§
Source§impl APIContextOptions
impl APIContextOptions
Sourcepub fn base_url(self, url: impl Into<String>) -> Self
pub fn base_url(self, url: impl Into<String>) -> Self
Set the base URL for all requests.
Relative URLs passed to request methods will be resolved against this base URL.
§Example
use viewpoint_core::api::APIContextOptions;
let options = APIContextOptions::new()
.base_url("https://api.example.com/v1");
// Now api.get("/users") will request https://api.example.com/v1/usersSourcepub fn extra_http_headers(
self,
headers: impl IntoIterator<Item = (String, String)>,
) -> Self
pub fn extra_http_headers( self, headers: impl IntoIterator<Item = (String, String)>, ) -> Self
Set extra HTTP headers to include in all requests.
§Example
use viewpoint_core::api::APIContextOptions;
let options = APIContextOptions::new()
.extra_http_headers([
("Authorization".to_string(), "Bearer token".to_string()),
("X-API-Key".to_string(), "secret".to_string()),
]);Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a single extra HTTP header.
Sourcepub fn http_credentials(self, credentials: HttpCredentials) -> Self
pub fn http_credentials(self, credentials: HttpCredentials) -> Self
Set HTTP credentials for Basic authentication.
§Example
use viewpoint_core::api::{APIContextOptions, HttpCredentials};
let options = APIContextOptions::new()
.http_credentials(HttpCredentials::new("user", "pass"));Sourcepub fn ignore_https_errors(self, ignore: bool) -> Self
pub fn ignore_https_errors(self, ignore: bool) -> Self
Set whether to ignore HTTPS certificate errors.
Warning: This should only be used for testing. Never use this in production as it makes the connection vulnerable to man-in-the-middle attacks.
Sourcepub fn proxy(self, proxy: ProxyConfig) -> Self
pub fn proxy(self, proxy: ProxyConfig) -> Self
Set proxy configuration.
§Example
use viewpoint_core::api::{APIContextOptions, ProxyConfig};
let options = APIContextOptions::new()
.proxy(ProxyConfig::new("http://proxy.example.com:8080")
.credentials("user", "pass"));Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Set the default timeout for all requests.
This can be overridden on a per-request basis.
Sourcepub fn user_agent(self, user_agent: impl Into<String>) -> Self
pub fn user_agent(self, user_agent: impl Into<String>) -> Self
Set the user agent string.
Trait Implementations§
Source§impl Clone for APIContextOptions
impl Clone for APIContextOptions
Source§fn clone(&self) -> APIContextOptions
fn clone(&self) -> APIContextOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for APIContextOptions
impl Debug for APIContextOptions
Source§impl Default for APIContextOptions
impl Default for APIContextOptions
Source§fn default() -> APIContextOptions
fn default() -> APIContextOptions
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for APIContextOptions
impl RefUnwindSafe for APIContextOptions
impl Send for APIContextOptions
impl Sync for APIContextOptions
impl Unpin for APIContextOptions
impl UnwindSafe for APIContextOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more