Access unix sockets via Reqwest crate

I want to access LXD API via local unix socket, according to docs we can access /1.0/instances endpoint to get list of container instances.
I tried with curl and it works:

> curl --unix-socket /var/snap/lxd/common/lxd/unix.socket lxd/1.0/instances

> {"type":"sync","status":"Success","status_code":200,"operation":"","error_code":0,"error":"","metadata":["/1.0/instances/machine-1"]}

I tried same via Reqwest but getting an error:

let base_url = "unix:///var/snap/lxd/common/lxd/unix.socket"; // tried with unix:/ and unix://
let url = self.base_url.join("lxd/1.0/instances")?;
let response = self.client.get(url).send().await?;

Error:

running 1 test
thread 'x::tests::test_list_of_instances' panicked at 'called `Result::unwrap()` on an `Err` value:
builder error for url (unix:///var/snap/lxd/common/lxd/lxd/1.0/instances): URL scheme is not allowed

Am I making an obvious mistake and missing it?

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.