Skip to main content

GcpHttpClient

Struct GcpHttpClient 

Source
pub struct GcpHttpClient { /* private fields */ }
Expand description

Authenticated, bounded HTTP client for Google Cloud REST APIs.

Consolidates the pattern shared by every Vertex backend in the workspace: cached ADC auth headers (honoring CacheableResource semantics), a redirect-disabled reqwest client with connect and request timeouts, HTTPS-or-loopback endpoint validation, and bounded JSON response reads with typed, consumer-branded errors.

§Example

use adk_core::ErrorComponent;
use adk_gcp::{GcpErrorCodes, GcpErrorContext, GcpHttpClient};
use serde_json::json;

const CODES: GcpErrorCodes = GcpErrorCodes {
    invalid_input: "memory.vertex.invalid_input",
    unauthorized: "memory.vertex.unauthorized",
    forbidden: "memory.vertex.forbidden",
    not_found: "memory.vertex.not_found",
    rate_limited: "memory.vertex.rate_limited",
    timeout: "memory.vertex.timeout",
    unavailable: "memory.vertex.unavailable",
    credentials_unavailable: "memory.vertex.credentials_unavailable",
    invalid_response: "memory.vertex.invalid_response",
    invalid_request: "memory.vertex.invalid_request",
    upstream_error: "memory.vertex.upstream_error",
    operation_failed: "memory.vertex.operation_failed",
};

let client = GcpHttpClient::builder(
    GcpErrorContext::new(ErrorComponent::Memory, CODES, "vertex memory"),
    "https://us-central1-aiplatform.googleapis.com",
)
.build()?;

let request = client
    .request(reqwest::Method::POST, "projects/p/locations/l/reasoningEngines/1/memories:generate")
    .await?
    .json(&json!({ "scope": { "app_name": "app" } }));
let operation = client.send_value(request).await?;

Implementations§

Source§

impl GcpHttpClient

Source

pub fn builder( errors: GcpErrorContext, endpoint: impl Into<String>, ) -> GcpHttpClientBuilder

Starts building a client for the given error identity and endpoint.

Source

pub fn errors(&self) -> &GcpErrorContext

The error identity this client stamps on failures.

Source

pub fn max_response_bytes(&self) -> usize

The configured maximum response size in bytes.

Source

pub fn with_max_response_bytes(self, max_response_bytes: usize) -> Self

Overrides the maximum accepted response size after construction.

Lets consumers expose their own post-construction bound override without rebuilding credentials. The caller is responsible for selecting a bound appropriate for the deployment.

Source

pub fn url(&self, path: &str) -> Result<Url>

Builds the absolute URL for an API path (version prefix applied).

§Errors

Returns an error when the resulting URL cannot be constructed.

Source

pub async fn request( &self, method: Method, path: &str, ) -> Result<RequestBuilder>

Builds an authorized request for an API path.

§Errors

Returns an error when credential headers cannot be acquired within the configured auth timeout.

Source

pub async fn apply_auth( &self, request: RequestBuilder, ) -> Result<RequestBuilder>

Applies cached credential headers to a request.

§Errors

Returns an error when credential headers cannot be acquired within the configured auth timeout.

Source

pub async fn auth_headers(&self) -> Result<HeaderMap>

Acquires credential headers, serving cached headers on NotModified.

§Errors

Returns an error when acquisition times out, the credential source fails, or the source reports NotModified before any headers were cached.

Source

pub async fn send_value(&self, request: RequestBuilder) -> Result<Value>

Sends a request and parses the response as JSON.

Empty or whitespace-only success bodies parse as an empty object.

§Errors

Returns an error when the request times out, transport fails, the response exceeds the configured size bound, the status is not a success, or the body is not valid JSON.

Source

pub async fn send_value_counted( &self, request: RequestBuilder, ) -> Result<(Value, usize)>

Sends a request, returning the parsed JSON and the decoded body size.

The byte count lets paginated callers enforce an aggregate response bound across pages.

§Errors

Returns the same errors as send_value.

Source

pub async fn send_value_allow_not_found( &self, request: RequestBuilder, ) -> Result<Option<Value>>

Sends a request, mapping 404 Not Found to Ok(None).

§Errors

Returns the same errors as send_value, except a 404 status which becomes Ok(None).

Trait Implementations§

Source§

impl Debug for GcpHttpClient

Source§

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

Formats the value using the given formatter. 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> 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: Sized + 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: Sized + 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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