kode_bridge/
ipc_client.rs1use std::path::Path;
2
3use interprocess::local_socket::tokio::prelude::LocalSocketStream;
4use interprocess::local_socket::traits::tokio::Stream;
5use interprocess::local_socket::{GenericFilePath, Name, ToFsName};
6
7use crate::errors::AnyResult;
8use crate::types::Response;
9use crate::http_client::http_request;
10
11pub struct IpcHttpClient {
13 name: Name<'static>,
14}
15
16impl IpcHttpClient {
17 pub fn new<P: AsRef<Path>>(path: P) -> AnyResult<Self> {
22 let name = path
23 .as_ref()
24 .to_fs_name::<GenericFilePath>()?
25 .into_owned();
26 Ok(Self { name })
27 }
28
29 pub async fn request(
36 &self,
37 method: &str,
38 path: &str,
39 body: Option<&serde_json::Value>,
40 ) -> AnyResult<Response> {
41 let stream = LocalSocketStream::connect(self.name.clone()).await?;
42 http_request(stream, method, path, body).await
43 }
44}