Skip to main content

ApiClient

Struct ApiClient 

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

HTTP API client for Conductor server.

Thread-safe and cloneable. Multiple clones share the same connection pool and authentication state.

§Authentication

The client automatically handles authentication when credentials are configured:

  • Fetches tokens from /token endpoint using key/secret
  • Proactively refreshes tokens before TTL expiration (default: 45 min)
  • Automatically retries requests on 401 after refreshing token
  • Gracefully handles OSS Conductor (no auth endpoint returns 404)

§Environment Variables

Configure via environment variables or .env file:

  • CONDUCTOR_SERVER_URL: Server API URL (default: http://localhost:8080/api)
  • CONDUCTOR_AUTH_KEY: Authentication key ID (Orkes Conductor)
  • CONDUCTOR_AUTH_SECRET: Authentication secret (Orkes Conductor)
  • CONDUCTOR_AUTH_TOKEN_TTL_MINS: Token TTL in minutes (default: 45)
  • CONDUCTOR_DEBUG: Enable debug logging (true/false)
  • CONDUCTOR_TIMEOUT_SECS: Request timeout in seconds (default: 30)

Implementations§

Source§

impl ApiClient

Source

pub fn new(config: Configuration) -> Result<Self>

Create a new API client.

The client will automatically handle authentication if credentials are configured via CONDUCTOR_AUTH_KEY and CONDUCTOR_AUTH_SECRET environment variables, or via Configuration::with_auth().

§Errors

Returns crate::error::ConductorError::Http if the underlying reqwest client fails to build (e.g. TLS backend initialization failure) – this doesn’t make any network request.

Source

pub fn base_url(&self) -> &str

Get the base URL.

Source

pub fn set_http_observer(&mut self, observer: Arc<dyn HttpMetricsObserver>)

Install an HTTP metrics observer on an existing client.

All subsequent clones share the same observer via Arc.

Source

pub async fn get<T>(&self, path: impl Into<ApiPath<'_>>) -> Result<T>

GET request.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn get_text(&self, path: impl Into<ApiPath<'_>>) -> Result<String>

GET request returning raw text (for endpoints that respond with text/plain rather than JSON, e.g. secret values)

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn get_with_params<T>( &self, path: impl Into<ApiPath<'_>>, params: &[(&str, &str)], ) -> Result<T>

GET request with query parameters.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn get_stream(&self, path: impl Into<ApiPath<'_>>) -> Result<Response>

GET request that returns the raw, unbuffered Response instead of deserializing it.

For endpoints whose body is consumed incrementally (e.g. Server-Sent Events) rather than parsed as a single JSON document. Applies the same auth-header/refresh handling as get, but does not retry on 401 — a streaming caller has already begun reading the body by the time a status past the headers would be observed, so there is no safe point to re-issue the request transparently.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn post<B, T>( &self, path: impl Into<ApiPath<'_>>, body: &B, ) -> Result<T>

POST request.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn post_text<B>( &self, path: impl Into<ApiPath<'_>>, body: &B, ) -> Result<String>
where B: Serialize,

POST request returning raw text.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn put<B, T>( &self, path: impl Into<ApiPath<'_>>, body: &B, ) -> Result<T>

PUT request.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn delete<T>(&self, path: impl Into<ApiPath<'_>>) -> Result<T>

DELETE request.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn delete_no_content( &self, path: impl Into<ApiPath<'_>>, ) -> Result<()>

DELETE request with no response body.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn delete_with_body<B>( &self, path: impl Into<ApiPath<'_>>, body: &B, ) -> Result<()>
where B: Serialize + ?Sized,

DELETE request with body.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn delete_with_params( &self, path: impl Into<ApiPath<'_>>, params: &[(&str, &str)], ) -> Result<()>

DELETE request with query parameters.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn post_no_response<B>( &self, path: impl Into<ApiPath<'_>>, body: &B, ) -> Result<()>
where B: Serialize + ?Sized,

POST request with no response.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn post_no_body<T>(&self, path: impl Into<ApiPath<'_>>) -> Result<T>

POST request with no body.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn post_no_body_no_response( &self, path: impl Into<ApiPath<'_>>, ) -> Result<()>

POST request with no body and no response.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn put_no_response<B>( &self, path: impl Into<ApiPath<'_>>, body: &B, ) -> Result<()>
where B: Serialize + ?Sized,

PUT request with no response.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn put_no_body(&self, path: impl Into<ApiPath<'_>>) -> Result<()>

PUT request with no request body and no response body

For endpoints mapped as a bare @PutMapping with no @RequestBody – e.g. /scheduler/schedules/{name}/pause. Sends no payload and no Content-Type at all, rather than a JSON null.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn put_raw( &self, path: impl Into<ApiPath<'_>>, body: &str, ) -> Result<()>

PUT request with raw text body.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn post_with_params<B, T>( &self, path: impl Into<ApiPath<'_>>, body: &B, params: &[(&str, &str)], ) -> Result<T>

POST request with JSON body and query parameters.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn post_raw_with_params( &self, path: impl Into<ApiPath<'_>>, body: &str, params: &[(&str, &str)], ) -> Result<()>

POST request with raw text body and query parameters.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn put_raw_with_params( &self, path: impl Into<ApiPath<'_>>, body: &str, params: &[(&str, &str)], ) -> Result<()>

PUT request with raw text body and query parameters.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn get_no_response(&self, path: impl Into<ApiPath<'_>>) -> Result<()>

GET request with no response.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, or an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status.

Source

pub async fn force_refresh_token(&self) -> Result<()>

Force refresh the authentication token.

Called when a request fails with 401, indicating the token may have been invalidated server-side before TTL expiration.

§Errors

Returns crate::error::ConductorError::Http if the request fails at the transport level, an crate::error::ConductorError::Auth/crate::error::ConductorError::Api/crate::error::ConductorError::Server variant if the server responds with a non-2xx status, or crate::error::ConductorError::Json if the response body can’t be deserialized.

Source

pub async fn is_oss(&self) -> bool

Check whether the server is OSS Conductor (vs Orkes Enterprise).

Probes POST /token with dummy credentials on first call and caches the result. OSS Conductor returns 404 (the endpoint does not exist); Enterprise returns a non-404 status (e.g. 401/403 for invalid creds).

This mirrors the detection strategy used by the JavaScript SDK.

Source

pub async fn get_config(&self) -> Configuration

Get configuration (for reading settings).

Trait Implementations§

Source§

impl Clone for ApiClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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

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