pub struct Clash { /* private fields */ }
Expand description
§Clash API
Use struct Clash
for interacting with Clash RESTful API.
For more information, check https://github.com/Dreamacro/clash/wiki/external-controller-API-reference###Proxies,
or maybe just read source code of clash
Implementations§
Source§impl Clash
impl Clash
pub fn builder<S: Into<String>>(url: S) -> Result<ClashBuilder>
pub fn new(url: Url) -> Self
Sourcepub fn oneshot_req_with_body(
&self,
endpoint: &str,
method: &str,
body: Option<String>,
) -> Result<String>
pub fn oneshot_req_with_body( &self, endpoint: &str, method: &str, body: Option<String>, ) -> Result<String>
Send a oneshot request to the specific endpoint with method, with body
Sourcepub fn oneshot_req(&self, endpoint: &str, method: &str) -> Result<String>
pub fn oneshot_req(&self, endpoint: &str, method: &str) -> Result<String>
Send a oneshot request to the specific endpoint with method, without body
Sourcepub fn longhaul_req<T: DeserializeOwned>(
&self,
endpoint: &str,
method: &str,
) -> Result<LongHaul<T>>
pub fn longhaul_req<T: DeserializeOwned>( &self, endpoint: &str, method: &str, ) -> Result<LongHaul<T>>
Send a longhaul request to the specific endpoint with method, Underlying is an http stream with chunked-encoding.
Use LongHaul::next_item
, LongHaul::next_raw
or Iterator::next
to retreive data
§Examplel
let traffics = clash.longhaul_req::<Traffic>("traffic", "GET").expect("connect failed");
// LongHaul implements `Iterator` so you can use iterator combinators
for traffic in traffics.take(3) {
println!("{:#?}", traffic)
}
Sourcepub fn get<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>
pub fn get<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>
Helper function for method GET
Sourcepub fn put<T: DeserializeOwned>(
&self,
endpoint: &str,
body: Option<String>,
) -> Result<T>
pub fn put<T: DeserializeOwned>( &self, endpoint: &str, body: Option<String>, ) -> Result<T>
Helper function for method PUT
Sourcepub fn get_version(&self) -> Result<Version>
pub fn get_version(&self) -> Result<Version>
Get clash version
Sourcepub fn get_configs(&self) -> Result<Config>
pub fn get_configs(&self) -> Result<Config>
Get base configs
Sourcepub fn reload_configs(&self, force: bool, path: &str) -> Result<()>
pub fn reload_configs(&self, force: bool, path: &str) -> Result<()>
Reloading base configs.
force
: will change ports etc.,path
: the absolute path to config file
This will NOT affect external-controller
& secret
Sourcepub fn get_proxies(&self) -> Result<Proxies>
pub fn get_proxies(&self) -> Result<Proxies>
Get proxies information
Sourcepub fn get_connections(&self) -> Result<Connections>
pub fn get_connections(&self) -> Result<Connections>
Get connections information
Sourcepub fn close_connections(&self) -> Result<()>
pub fn close_connections(&self) -> Result<()>
Close all connections
Sourcepub fn close_one_connection(&self, id: &str) -> Result<()>
pub fn close_one_connection(&self, id: &str) -> Result<()>
Close specific connection
Sourcepub fn get_traffic(&self) -> Result<LongHaul<Traffic>>
pub fn get_traffic(&self) -> Result<LongHaul<Traffic>>
Get real-time traffic data
Note: This is a longhaul request, which will last forever until interrupted or disconnected.
See longhaul_req
for more information
Sourcepub fn get_log(&self) -> Result<LongHaul<Log>>
pub fn get_log(&self) -> Result<LongHaul<Log>>
Get real-time logs
Note: This is a longhaul request, which will last forever until interrupted or disconnected.
See longhaul_req
for more information