Skip to main content

KibanaClient

Struct KibanaClient 

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

Kibana client for making API requests.

The client can operate in two modes:

  • Root mode (space: None): For global operations like managing spaces
  • Space mode (space: Some(id)): For space-scoped operations

Use .space(id) to create a space-scoped client from a root client.

§Example

use kibana_sync::{Auth, KibanaClient};
use url::Url;

let url = Url::parse("http://localhost:5601")?;
let client = KibanaClient::builder(url)
    .auth(Auth::None)
    .spaces([("marketing".to_string(), "Marketing".to_string())])
    .build()?;

// Root client for global operations (e.g., managing spaces)
let response = client.get("/api/spaces/space").await?;

// Space-scoped client for space-specific operations
let marketing = client.space("marketing")?;
let objects = marketing.get("/api/saved_objects/_find").await?;

// Get the current space ID
assert_eq!(marketing.space_id(), "marketing");

Implementations§

Source§

impl KibanaClient

Source

pub fn builder(url: Url) -> KibanaClientBuilder

Start configuring a root Kibana client from explicit values.

Source

pub fn new(url: Url, auth: Auth) -> Result<Self>

Create a root client with default options and only the default space.

Source

pub fn space(&self, id: &str) -> Result<KibanaClient>

Create a space-scoped client for the given space ID.

Returns a new client that will automatically scope all API requests to the specified space (prefixing paths with /s/{space}/).

§Arguments
  • id - Space ID to scope to
§Returns

A new KibanaClient scoped to the specified space

§Errors

Returns an error if the space ID is not in the loaded manifest

§Example
let marketing = client.space("marketing")?;
assert_eq!(marketing.space_id(), "marketing");
Source

pub async fn server_version_info(&self) -> Result<KibanaVersionInfo>

Resolve and cache Kibana server version info from /api/status.

Source

pub async fn server_version(&self) -> Result<KibanaVersion>

Resolve the normalized Kibana server version.

Source

pub fn supports_capability( version: &KibanaVersion, capability: ApiCapability, ) -> bool

Check if a capability is supported on a specific Kibana version.

Source

pub fn unsupported_capability_reason( version: &KibanaVersion, capability: ApiCapability, ) -> String

Build a user-facing unsupported message for a capability/version pair.

Source

pub fn space_id(&self) -> &str

Get the current space ID.

Returns “default” for root mode or the default space.

Source

pub fn is_root(&self) -> bool

Check if this client is in root mode (no space scoping).

Source

pub fn space_ids(&self) -> Vec<&str>

Get all available space IDs from the manifest.

Source

pub fn space_name(&self, id: &str) -> Option<&str>

Get the name of a space by ID.

§Returns

The space name if found, None otherwise

Source

pub fn has_space(&self, id: &str) -> bool

Check if a space exists in the manifest.

Source

pub fn url(&self) -> &Url

Get the base URL.

Source

pub async fn test_connection(&self) -> Result<Response>

Verify the connection and authentication to Kibana.

Makes a GET request to /api/status to verify connectivity.

Source

pub async fn request( &self, method: Method, headers: &HashMap<String, String>, path: &str, body: Option<&[u8]>, ) -> Result<Response>

Send a request to a given path.

If this client is scoped to a space, the path will be prefixed with /s/{space}/. For root mode, the path is used as-is.

§Arguments
  • method - HTTP method
  • headers - Additional headers
  • path - API path
  • body - Optional request body
Source

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

Helper for GET requests.

Source

pub async fn get_internal(&self, path: &str) -> Result<Response>

Helper for GET requests for internal Kibana APIs. Adds X-Elastic-Internal-Origin header required by some APIs (e.g., workflows).

Source

pub async fn head(&self, path: &str) -> Result<Response>

Helper for HEAD requests.

Source

pub async fn head_internal(&self, path: &str) -> Result<Response>

Helper for HEAD requests for internal Kibana APIs. Adds X-Elastic-Internal-Origin header required by some APIs.

Source

pub async fn post_json(&self, path: &str, body: &[u8]) -> Result<Response>

Helper for POST requests with JSON body.

Source

pub async fn post_json_value( &self, path: &str, value: &Value, ) -> Result<Response>

Helper for POST requests with JSON value.

Source

pub async fn post_json_value_internal( &self, path: &str, value: &Value, ) -> Result<Response>

Helper for POST requests with JSON value for internal Kibana APIs. Adds X-Elastic-Internal-Origin header required by some APIs (e.g., workflows).

Source

pub async fn put_json_value( &self, path: &str, value: &Value, ) -> Result<Response>

Helper for PUT requests with JSON value.

Source

pub async fn put_json_value_internal( &self, path: &str, value: &Value, ) -> Result<Response>

Helper for PUT requests with JSON value for internal Kibana APIs. Adds X-Elastic-Internal-Origin header required by some APIs (e.g., workflows).

Source

pub async fn post_form(&self, path: &str, body: &[u8]) -> Result<Response>

Helper for POST requests with multipart form data.

Trait Implementations§

Source§

impl Clone for KibanaClient

Source§

fn clone(&self) -> KibanaClient

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

impl Debug for KibanaClient

Source§

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

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

impl Display for KibanaClient

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> 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: 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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