Skip to content

Commit

Permalink
Demo API client.
Browse files Browse the repository at this point in the history
To try this out, run:
cargo run api grpc --port 8888

Then run cargo run api_client
  • Loading branch information
matts1 committed Apr 30, 2024
1 parent f994626 commit ff518a0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = []

[workspace]
resolver = "2"
members = [ "api", "cli", "lib", "lib/gen-protos", "lib/proc-macros", "lib/testutils"]
members = [ "api", "api_client","cli", "lib", "lib/gen-protos", "lib/proc-macros", "lib/testutils"]

[workspace.package]
version = "0.16.0"
Expand Down Expand Up @@ -102,6 +102,7 @@ tokio = { version = "1.37.0", features = ["rt", "macros"] }
toml_edit = { version = "0.19.15", features = ["serde"] }
tonic = "0.11.0"
tonic-build = "0.11.0"
tonic-reflection = "0.11.0"
tonic-web = "0.11.0"
tracing = "0.1.40"
tracing-chrome = "0.7.2"
Expand Down
19 changes: 19 additions & 0 deletions api_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "api_client"
version.workspace = true
license.workspace = true
rust-version.workspace = true
edition.workspace = true
readme.workspace = true
homepage.workspace = true
repository.workspace = true
documentation.workspace = true
categories.workspace = true
keywords.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tonic.workspace = true
jj-api.workspace = true
tokio = { workspace = true, features = ["full"] }
15 changes: 15 additions & 0 deletions api_client/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use jj_api::client::JjServiceClient;
use jj_api::rpc::ListWorkspacesRequest;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = JjServiceClient::connect("http://[::1]:8888").await?;

let request = tonic::Request::new(ListWorkspacesRequest::default());

let response = client.list_workspaces(request).await?;

println!("RESPONSE={:?}", response);

Ok(())
}

0 comments on commit ff518a0

Please sign in to comment.