APIContextOptions

Struct APIContextOptions 

Source
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

Source

pub fn new() -> Self

Create a new options builder with default settings.

Source

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/users
Source

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()),
    ]);
Source

pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self

Add a single extra HTTP header.

Source

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"));
Source

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.

Source

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"));
Source

pub fn timeout(self, timeout: Duration) -> Self

Set the default timeout for all requests.

This can be overridden on a per-request basis.

Source

pub fn user_agent(self, user_agent: impl Into<String>) -> Self

Set the user agent string.

Trait Implementations§

Source§

impl Clone for APIContextOptions

Source§

fn clone(&self) -> APIContextOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for APIContextOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for APIContextOptions

Source§

fn default() -> APIContextOptions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more