pub struct UnifiClient {
pub url: String,
/* private fields */
}Expand description
HTTP REST client for UniFi controllers.
Supports both modern UniFi OS controllers (behind /proxy/network) and
legacy controllers (no prefix, typically port 8443). Authentication uses
the X-API-KEY header.
Builds and holds one pooled [reqwest::Client] for its lifetime — clone
and share a UnifiClient rather than constructing a new one per request,
so requests reuse connections instead of paying a fresh TLS handshake
each time.
Debug redacts the API key, same as UnifiConfig.
Fields§
§url: StringBase URL, e.g. https://unifi.local, with any trailing slash trimmed.
Implementations§
Source§impl UnifiClient
impl UnifiClient
Sourcepub fn new(cfg: &UnifiConfig) -> Result<Self>
pub fn new(cfg: &UnifiConfig) -> Result<Self>
Builds a client from cfg.
§Errors
Returns UnifiError::MissingUrl or UnifiError::MissingApiKey if the
corresponding config field is empty, or UnifiError::ClientBuild if the
underlying HTTP client fails to construct.
Sourcepub fn legacy(&self) -> bool
pub fn legacy(&self) -> bool
Whether this client targets a legacy controller (no /proxy/network prefix).
Sourcepub fn config(&self) -> UnifiConfig
pub fn config(&self) -> UnifiConfig
Reconstructs the UnifiConfig this client was built from.
Sourcepub async fn request_json(
&self,
action: &str,
method: Method,
path: &str,
query: Option<&Value>,
body: Option<&Value>,
) -> Result<Value>
pub async fn request_json( &self, action: &str, method: Method, path: &str, query: Option<&Value>, body: Option<&Value>, ) -> Result<Value>
Issues a request against this client’s controller, reusing its pooled
connection. This is the primitive the dynamic action dispatcher
(crate::ActionDispatcher) builds on; the named methods below
(clients, devices, …) are thin, discoverable wrappers around it.
action is a friendly name (e.g. "clients", "official_list_sites")
used only for tracing — see http::request_json.
§Errors
See UnifiError for the failure cases this can return.
Sourcepub async fn clients(&self) -> Result<Value>
pub async fn clients(&self) -> Result<Value>
Connected clients (wireless and wired).
§Errors
See UnifiError for the failure cases this can return.
Sourcepub async fn devices(&self) -> Result<Value>
pub async fn devices(&self) -> Result<Value>
Network devices: APs, switches, gateways.
§Errors
See UnifiError for the failure cases this can return.
Trait Implementations§
Source§impl Clone for UnifiClient
impl Clone for UnifiClient
Source§fn clone(&self) -> UnifiClient
fn clone(&self) -> UnifiClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more