Crates.io | centraldogma |
lib.rs | centraldogma |
version | 0.1.2 |
source | src |
created_at | 2021-06-07 07:17:12.164167 |
updated_at | 2022-01-05 01:55:35.647677 |
description | CentralDogma client for Rust |
homepage | https://github.com/line/centraldogma-rs |
repository | |
max_upload_size | |
id | 407200 |
size | 126,226 |
Official Rust Client for Central Dogma.
Full documentation is available at https://docs.rs/centraldogma
Add centraldogma
crate and version to Cargo.toml.
centraldogma = "0.1.0"
The client uses reqwest
to make HTTP calls, which internally uses
the tokio
runtime for async support. As such, you may require to take
a dependency on tokio
in order to use the client.
tokio = { version = "1.2.0", features = ["full"] }
Create a new client to make API to CentralDogma using the Client
struct.
use centraldogma::Client;
#[tokio::main]
fn main() {
// with token
let client = Client::new("http://localhost:36462", Some("token")).await.unwrap();
// without token
let client = Client::new("http://localhost:36462", None).await.unwrap();
// your code ...
}
Typed API calls are provided behind traits:
use centraldogma::{Client, ContentService};
#[tokio::main]
fn main() {
// without token
let client = Client::new("http://localhost:36462", None).await.unwrap();
let file = client
.repo("project", "repository")
.get_file(Revision::HEAD, Query::of_text("/a.yml"))
.await
.unwrap();
// your code ...
}
use centraldogma::{Client, ContentService};
#[tokio::main]
fn main() {
let client = Client::new("http://localhost:36462", None).await.unwrap();
let changes = vec![Change {
path: "/a.json".to_string(),
content: ChangeContent::UpsertJson(serde_json::json!({"a":"b"})),
}];
let result = client
.repo("foo", "bar")
.push(
Revision::HEAD,
CommitMessage::only_summary("Add a.json"),
changes,
)
.await
.unwrap();
use centraldogma::{Client, WatchService};
#[tokio::main]
fn main() {
let client = Client::new("http://localhost:36462", None).await.unwrap();
let stream = client
.repo("foo", "bar")
.watch_file_stream(&Query::identity("/a.json").unwrap())
.unwrap();
tokio::spawn(async move {
while let Some(result) = stream.next().await {
// your code ...
}
})
See CONTRIBUTING.md.