nucel-sdk-api 0.2.0

Auto-generated Rust client for the nucel.dev REST API (OpenAPI-driven, progenitor-built)
Documentation
//! Auto-generated Rust SDK for the nucel.dev REST API.
//!
//! The contents of this crate are generated at build time by [progenitor]
//! from `openapi/nucel.json` (the OpenAPI spec exported from the
//! `nucel-server` utoipa annotations).
//!
//! # Usage
//!
//! ```no_run
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = nucel_sdk_api::new("https://nucel.dev", Some("ghp_token".into()))?;
//! let repo = client.get_repo().owner("acme").repo("widgets").send().await?;
//! println!("{}", repo.into_inner());
//! # Ok(())
//! # }
//! ```
//!
//! [progenitor]: https://github.com/oxidecomputer/progenitor

#![allow(clippy::all, unused_imports, dead_code)]

include!(concat!(env!("OUT_DIR"), "/codegen.rs"));

/// Build a `Client` configured for `base_url` with an optional bearer token.
///
/// All requests issued through the returned client will include
/// `Authorization: Bearer <token>` if a token is provided.
pub fn new(
    base_url: impl Into<String>,
    token: Option<String>,
) -> Result<Client, reqwest::Error> {
    use reqwest::header;

    let mut headers = header::HeaderMap::new();
    if let Some(t) = token {
        let mut value = header::HeaderValue::from_str(&format!("Bearer {t}"))
            .expect("token contains invalid header bytes");
        value.set_sensitive(true);
        headers.insert(header::AUTHORIZATION, value);
    }
    headers.insert(
        header::USER_AGENT,
        header::HeaderValue::from_static(concat!("nucel-sdk-api/", env!("CARGO_PKG_VERSION"))),
    );

    let http = reqwest::Client::builder()
        .default_headers(headers)
        .build()?;

    Ok(Client::new_with_client(&base_url.into(), http))
}