Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/line/centraldogma-rs
Official Rust client for Central Dogma
https://github.com/line/centraldogma-rs
centraldogma reqwest rust rust-library tokio-rs
Last synced: about 2 months ago
JSON representation
Official Rust client for Central Dogma
- Host: GitHub
- URL: https://github.com/line/centraldogma-rs
- Owner: line
- License: apache-2.0
- Created: 2021-05-27T09:17:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T06:45:14.000Z (over 1 year ago)
- Last Synced: 2024-07-06T14:23:00.703Z (2 months ago)
- Topics: centraldogma, reqwest, rust, rust-library, tokio-rs
- Language: Rust
- Homepage: https://docs.rs/centraldogma
- Size: 113 KB
- Stars: 46
- Watchers: 12
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-list - centraldogma-rs
README
# centraldogma-rs
Official Rust Client for [Central Dogma](https://line.github.io/centraldogma/).
Full documentation is available at
## Getting started
### Installing
Add `centraldogma` crate and version to Cargo.toml.
```toml
centraldogma = "0.1"
```#### Async support with tokio
The client uses [`reqwest`](https://crates.io/crates/reqwest) to make HTTP calls, which internally uses
the [`tokio`](https://crates.io/crates/tokio) runtime for async support. As such, you may require to take
a dependency on `tokio` in order to use the client.```toml
tokio = { version = "1.2.0", features = ["full"] }
```### Create a client
Create a new client to make API to CentralDogma using the `Client` struct.
```rust,no_run
use centraldogma::Client;#[tokio::main]
async 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:
* [`ProjectService`](https://docs.rs/centraldogma/0.1.0/centraldogma/trait.ProjectService.html)
* [`RepoService`](https://docs.rs/centraldogma/0.1.0/centraldogma/trait.RepoService.html)
* [`ContentService`](https://docs.rs/centraldogma/0.1.0/centraldogma/trait.ContentService.html)
* [`WatchService`](https://docs.rs/centraldogma/0.1.0/centraldogma/trait.WatchService.html)#### Examples
##### Get File
```rust,no_run
use centraldogma::{
Client, ContentService,
model::{Revision, Query},
};#[tokio::main]
async 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").unwrap())
.await
.unwrap();
// your code ...
}
```##### Push
```rust,no_run
use centraldogma::{
Client, ContentService,
model::{Revision, Change, ChangeContent, CommitMessage},
};
use serde_json;#[tokio::main]
async 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
```rust,no_run
use centraldogma::{Client, WatchService, model::Query};
use futures::StreamExt;#[tokio::main]
async fn main() {
let client = Client::new("http://localhost:36462", None).await.unwrap();
let mut 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](CONTRIBUTING.md).