Skip to content

Commit 8a7f441

Browse files
Merge pull request #2447 from oasisprotocol/uniyalabhishek/feature/rofl-client-rs-http-transport
feat(rofl-client/rs): add HTTP transport
2 parents 38d18ee + 9aff4dc commit 8a7f441

File tree

7 files changed

+452
-96
lines changed

7 files changed

+452
-96
lines changed

.github/workflows/ci-test.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,8 @@ jobs:
626626
env:
627627
BUILDKITE_API_TOKEN: ${{ secrets.BUILDKITE_API_TOKEN }}
628628

629-
test-python-rofl-client:
630-
name: test-python-rofl-client
629+
test-rofl-client-python:
630+
name: test-rofl-client-python
631631
runs-on: ubuntu-latest
632632
steps:
633633
- name: Checkout code
@@ -648,3 +648,16 @@ jobs:
648648
- name: Run tests
649649
working-directory: rofl-client/py
650650
run: uv run pytest tests
651+
652+
test-rofl-client-rust:
653+
name: test-rofl-client-rust
654+
runs-on: ubuntu-latest
655+
steps:
656+
- name: Checkout code
657+
uses: actions/checkout@v4
658+
659+
- name: Set up Rust
660+
run: rustup show
661+
662+
- name: Run tests
663+
run: cargo test -p oasis-rofl-client

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/rofl/workflow/test.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ client = RoflClient(url="./rofl-appd.sock")
6363
import { RoflClient } from '@oasisprotocol/rofl-client';
6464
const client = new RoflClient({ url: './rofl-appd.sock' });
6565
```
66+
67+
```rust title="Rust"
68+
use oasis_rofl_client::RoflClient;
69+
let client = RoflClient::with_socket_path("./rofl-appd.sock")?;
70+
```
6671
</TabItem>
6772
<TabItem value="TCP port (macOS, Linux)">
6873
```shell title="Shell"
@@ -80,6 +85,11 @@ client = RoflClient(url="http://localhost:8549")
8085
import { RoflClient } from '@oasisprotocol/rofl-client';
8186
const client = new RoflClient({ url: 'http://localhost:8549' });
8287
```
88+
89+
```rust title="Rust"
90+
use oasis_rofl_client::RoflClient;
91+
let client = RoflClient::with_url("http://localhost:8549")?;
92+
```
8393
</TabItem>
8494
</Tabs>
8595

rofl-client/rs/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ name = "oasis-rofl-client"
33
version = "0.1.0"
44
edition = "2021"
55
license = "Apache-2.0"
6-
description = "Rust client for ROFL appd (Unix domain socket HTTP)."
6+
description = "Rust client for ROFL appd over UNIX domain sockets and HTTP."
77

88
[dependencies]
99
serde = { version = "1", features = ["derive"] }
1010
serde_json = "1"
1111
tokio = { version = "1", features = ["full", "test-util"] }
1212
hex = "0.4.3"
13-
thiserror = "1.0"
14-
anyhow = "1.0"
1513

1614
[dev-dependencies]
1715
tempfile = "3.8"

rofl-client/rs/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# rofl-client/rs/README.md
2-
Rust client for the ROFL appd over a Unix domain socket.
2+
Rust client for the ROFL appd over UNIX domain sockets and plain HTTP.
33

44
- Default socket: `/run/rofl-appd.sock`
5+
- HTTP constructor: `RoflClient::with_url("http://localhost:8549")`
56
- Endpoints used:
67
- `GET /rofl/v1/app/id`
78
- `POST /rofl/v1/keys/generate`
89
- `POST /rofl/v1/tx/sign-submit`
10+
- `GET /rofl/v1/metadata`
11+
- `POST /rofl/v1/metadata`
12+
- `POST /rofl/v1/query`
913

1014
Quickstart:
1115

@@ -14,7 +18,11 @@ use oasis_rofl_client::{KeyKind, RoflClient};
1418

1519
#[tokio::main]
1620
async fn main() -> Result<(), Box<dyn std::error::Error>> {
17-
let client = RoflClient::new()?;
21+
let client = match std::env::var("ROFL_CLIENT_URL") {
22+
Ok(url) => RoflClient::with_url(&url)?,
23+
Err(_) => RoflClient::new()?,
24+
};
25+
1826
println!("app id: {}", client.get_app_id().await?);
1927
println!(
2028
"key: {}",
@@ -25,5 +33,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2533
```
2634

2735
Notes:
28-
- Requires Unix socks. Windows is not supported unless using WSL.
29-
- Methods are `async` and internally offload blocking UDS I/O via `tokio::task::spawn_blocking`.
36+
- `RoflClient::new()` and `RoflClient::with_socket_path()` keep using UNIX sockets.
37+
- `RoflClient::with_url()` accepts `http://...` URLs and custom socket paths; `https://...` is rejected explicitly.
38+
- Methods are `async` and internally offload blocking transport I/O via `tokio::task::spawn_blocking`.

rofl-client/rs/examples/basic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ use oasis_rofl_client::{KeyKind, RoflClient};
33

44
#[tokio::main]
55
async fn main() -> Result<(), Box<dyn std::error::Error>> {
6-
let client = RoflClient::new()?;
6+
let client = match std::env::var("ROFL_CLIENT_URL") {
7+
Ok(url) => RoflClient::with_url(&url)?,
8+
Err(_) => RoflClient::new()?,
9+
};
10+
711
println!("app id: {}", client.get_app_id().await?);
812
println!(
913
"key: {}",

0 commit comments

Comments
 (0)