ApiClient

Struct ApiClient 

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

API client, used to query CDF.

Implementations§

Source§

impl ApiClient

Source

pub fn new( api_base_url: &str, app_name: &str, client: ClientWithMiddleware, ) -> ApiClient

Create a new api client.

§Arguments
  • api_base_url - Base URL for CDF. For example https://api.cognitedata.com
  • app_name - App name added to the x-cdp-app header.
  • client - Underlying reqwest client.
Source

pub fn clone_with_api_version(&self, api_version: &str) -> ApiClient

Create a new api client with a custom API version. This will set the cdf-version header to the given value.

§Arguments
  • api_version - API version to use.
Source

pub async fn get<T: DeserializeOwned>(&self, path: &str) -> Result<T>

Perform a get request to the given path, deserializing the result from JSON.

§Arguments
  • path - Request path, without leading slash.
Source

pub async fn get_with_params<T: DeserializeOwned, R: IntoParams>( &self, path: &str, params: Option<R>, ) -> Result<T>

Perform a get request to the given path, with a query given by params, then deserialize the result from JSON.

§Arguments
  • path - Request path, without leading slash.
  • params - Optional object converted to query parameters.
Source

pub async fn get_stream( &self, url: &str, ) -> Result<impl TryStream<Ok = Bytes, Error = Error>>

Perform a get request to the given URL, returning a stream.

§Arguments
  • url - Full URL to get stream from.
Source

pub async fn post<D, S>(&self, path: &str, object: &S) -> Result<D>

Perform a post request to the given path, serializing object to JSON and sending it as the body, then deserialize the response from JSON.

§Arguments
  • path - Request path, without leading slash.
  • object - Object converted to JSON body.
Source

pub fn get_request(&self, path: &str) -> RequestBuilder<'_, ()>

Create a request builder for a GET request to path.

Source

pub fn post_request(&self, path: &str) -> RequestBuilder<'_, ()>

Create a request builder for a POST request to path.

Source

pub fn put_request(&self, path: &str) -> RequestBuilder<'_, ()>

Create a request builder for a PUT request to path.

Source

pub fn delete_request(&self, path: &str) -> RequestBuilder<'_, ()>

Create a request builder for a Delete request to path.

Source

pub async fn post_with_query<D: DeserializeOwned, S: Serialize, R: IntoParams>( &self, path: &str, object: &S, params: Option<R>, ) -> Result<D>

Perform a post request to the given path, with query parameters given by params. Deserialize the response from JSON.

  • path - Request path, without leading slash.
  • object - Object converted to JSON body.
  • params - Object converted to query parameters.
Source

pub async fn post_protobuf<D: DeserializeOwned + Send + Sync, T: Message>( &self, path: &str, value: &T, ) -> Result<D>

Perform a post request to the given path, posting value as protobuf. Expects JSON as response.

§Arguments
  • path - Request path without leading slash.
  • value - Protobuf value to post.
Source

pub async fn post_expect_protobuf<D: Message + Default, S: Serialize>( &self, path: &str, object: &S, ) -> Result<D>

Perform a post request to the given path, send object as JSON in the body, then expect protobuf as response.

§Arguments
  • path - Request path without leading slash.
  • object - Object to convert to JSON and post.
Source

pub async fn put_blob( &self, url: &str, mime_type: &str, data: impl Into<Bytes>, ) -> Result<()>

Perform a put request with the data in data.

§Arguments
  • url - URL to stream blob to.
  • mime_type - What to put in the X-Upload_Content-Type header.
  • data - Data to upload.
Source

pub async fn put_stream<S>( &self, url: &str, mime_type: &str, stream: S, stream_chunked: bool, known_size: Option<u64>, ) -> Result<()>
where S: TryStream + Send + 'static, S::Error: Into<Box<dyn Error + Send + Sync + 'static>>, Bytes: From<S::Ok>,

Perform a put request, streaming data to url.

§Arguments
  • url - URL to stream blob to.
  • mime_type - What to put in the X-Upload_Content-Type header.
  • stream - Stream to upload.
  • stream_chunked - If true, use chunked streaming to upload the data.
  • known_size - Set the Content-Length header to this value.

If known_size is None and stream_chunked is true, the request will be uploaded using special chunked streaming logic. Some backends do not support this.

If stream_chunked is true and known_size is Some, this will include a content length header, it is highly recommended to set this whenever possible.

§Warning

If stream_chunked is false, this will collect the input stream into a memory, which can be very expensive.

Source

pub async fn put<D, S>(&self, path: &str, object: &S) -> Result<D>

Perform a put request to path with object as JSON, expecting JSON in return.

§Arguments
  • path - Request path without leading slash.
  • object - Object to send as JSON.
Source

pub async fn delete<T: DeserializeOwned>(&self, path: &str) -> Result<T>

Perform a delete request to path, expecting JSON as response.

§Arguments
  • path - Request path without leading slash.
Source

pub async fn delete_with_params<T: DeserializeOwned, R: IntoParams>( &self, path: &str, params: Option<R>, ) -> Result<T>

Perform a delete request to path, with query parameters given by params.

§Arguments
  • path - Request path without leading slash.
  • params - Object converted to query parameters.
Source

pub async fn send_request( &self, request_builder: RequestBuilder, ) -> Result<Response>

Send an arbitrary HTTP request using the client. This will not parse the response, but will append authentication headers and retry with the same semantics as any normal API call.

§Arguments
  • request_builder - Request to send.
Source

pub fn client(&self) -> &ClientWithMiddleware

Get the inner HTTP client.

Source

pub fn app_name(&self) -> &str

Get the configured app name.

Source

pub fn api_base_url(&self) -> &str

Get the configured API base URL.

Source

pub fn api_version(&self) -> Option<&str>

Get the CDF API version this client will use. Any requests made with the request builder will append a header cdf-version with this value, if it is set.

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> IntoPatchItem<UpdateSet<T>> for T

Source§

fn patch(self, _options: &UpsertOptions) -> Option<UpdateSet<T>>

Convert self into a patch, optionally ignoring null values.
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, 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