3 releases

0.1.2 Jan 5, 2022
0.1.1 Jan 4, 2022
0.1.0 Jun 7, 2021

#241 in HTTP client

Download history 225/week @ 2023-12-07 262/week @ 2023-12-14 236/week @ 2023-12-21 7/week @ 2023-12-28 53/week @ 2024-01-04 177/week @ 2024-01-11 115/week @ 2024-01-18 256/week @ 2024-01-25 206/week @ 2024-02-01 122/week @ 2024-02-08 185/week @ 2024-02-15 87/week @ 2024-02-22 164/week @ 2024-02-29 85/week @ 2024-03-07 86/week @ 2024-03-14 26/week @ 2024-03-21

379 downloads per month

Apache-2.0

89KB
2K SLoC

centraldogma-rs

Official Rust Client for Central Dogma.

Full documentation is available at https://docs.rs/centraldogma

Getting started

Installing

Add centraldogma crate and version to Cargo.toml.

centraldogma = "0.1.0"

Async support with tokio

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 client

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 ...
}

Making typed API calls

Typed API calls are provided behind traits:

Examples

Get File
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 ...
}
Push
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();
Watch file change
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 ...
        }
    })

Contributing

See CONTRIBUTING.md.

Dependencies

~6–20MB
~300K SLoC