Expand description
§cnb — Rust client for the CNB (Cloud Native Build) platform.
An async, typed, production-grade SDK for the CNB public API, covering all 241 operations across 28 tag groups (repositories, issues, pulls, git, releases, builds, artifactories, workspaces, AI helpers, …).
This crate is not officially affiliated with CNB.
§Quick start
use cnb::ApiClient;
// Picks up `CNB_TOKEN` from the environment.
let client = ApiClient::new()?;
let me = client.users().get_user_info().await?;
println!("{me:?}");Every resource method returns a Result<T> where T is a
typed DTO from the models module (or serde_json::Value for endpoints
where the upstream spec did not pin a schema).
§Features
| Feature | Default | Description |
|---|---|---|
rustls-tls | ✓ | Use rustls as the TLS backend (no OpenSSL). |
native-tls | Use the system TLS (OpenSSL / Secure Transport). | |
retry | ✓ | Automatic retries with exponential back-off. |
tracing | Emit tracing spans for each API call. | |
stream | Stream-based pagination helpers. | |
all-resources | ✓ | Enable every resource module. Disable to slim. |
| per-resource | ✓ | activities, ai, …, workspace — see Cargo.toml. |
TLS backends are mutually exclusive. When disabling the default, pick one:
cnb = { version = "0.2", default-features = false, features = ["native-tls", "retry", "all-resources"] }§Error handling
All errors are a ApiError. Non-2xx responses preserve the raw body plus
any parsed code / message / request_id fields:
use cnb::{ApiClient, ApiError};
let client = ApiClient::new()?;
match client.repositories().get_by_id("owner/name".into()).await {
Ok(repo) => println!("{repo:?}"),
Err(ApiError::Http { status: 404, .. }) => println!("not found"),
Err(ApiError::Http { status, body, .. }) => println!("HTTP {status}: {body}"),
Err(e) => println!("transport error: {e}"),
}Modules§
- activities
activities - ai
ai - artifactory
artifactory - assets
assets - badge
badge - build
build - charge
charge - event
event - followers
followers - git
git - git_
settings git_settings - http
- Shared HTTP transport. All resource modules call into
HttpInner::executeorHttpInner::execute_with_body. - issues
issues - knowledge_
base knowledge_base - members
members - missions
missions - models
- Typed request / response DTOs generated from
definitionsin the CNB OpenAPI specification. - organizations
organizations - pagination
- Generic pagination helpers behind the
streamfeature. - pulls
pulls - rank
rank - registries
registries - releases
releases - repo_
code_ issue repo_code_issue - repo_
contributor repo_contributor - repo_
labels repo_labels - repositories
repositories - search
search - security
security - starring
starring - users
users - wiki
wiki - workspace
workspace
Structs§
- ApiClient
- Top-level entry point of the SDK.
- Client
Builder - Builder for
ApiClient. See module docs for examples. - Retry
Config - Retry configuration. Construct with
RetryConfig::defaultfor sensible defaults or adjust individual fields.
Enums§
- ApiError
- Every error surfaced by the SDK.
Constants§
- CNB_
API_ ACCEPT - Wire format the CNB API uses for successful JSON responses. We pre-set this
in the shared
reqwest::Client’s default headers so callers never need to think about it. - DEFAULT_
BASE_ URL - Default base URL — the production CNB endpoint.
- TOKEN_
ENV_ VAR - Environment variable consulted by
ClientBuilder::buildwhen no explicit token is provided.