Skip to main content

Crate incident_io

Crate incident_io 

Source
Expand description

Rust client for the incident.io API.

Everything under apis and models is generated from our published OpenAPI schema, so it tracks the live API: a function for every endpoint, and a type for every request and response.

§Quickstart

use incident_io::apis::{configuration::Configuration, incidents_v2_api};

let mut config = Configuration::new();
config.bearer_access_token = Some("my-api-key".to_owned());

let params = incidents_v2_api::IncidentsV2ListParams::new().set_page_size(25);
let result = incidents_v2_api::incidents_v2_list(&config, params).await?;

for incident in result.incidents {
    println!("{} {}", incident.reference, incident.name);
}

§Building a request

Every generated type is #[non_exhaustive], so that adding a field stays a backwards-compatible change. Struct literals and ..Default::default() therefore don’t compile from outside this crate; use new(), which takes the required fields, and the chainable set_* methods for the rest:

use incident_io::apis::incidents_v2_api::IncidentsV2ListParams;

let params = IncidentsV2ListParams::new()
    .set_page_size(100)
    .set_sort_by("created_at_newest_first");

A setter takes the value rather than Some(value). Reading a field is unchanged — they are all public.

new() takes the required fields on a params struct and on a request payload. On a response type it takes none: the API adds required properties to responses regularly, and a constructor that named them would break you every time it did.

apis::configuration::Configuration, apis::configuration::ApiKey, apis::ResponseContent and apis::Error are #[non_exhaustive] as well. An API change cannot add a field to those, but a generator upgrade can, so they are marked for the same reason and built the same way. apis::Error needs a wildcard arm when you match it.

Default::default() is not blocked by #[non_exhaustive], and every model derives it. On a type with required fields it hands back empty strings, which the API rejects with a 422 — use new() instead.

§Unknown enum values

We add values to enums as a backwards-compatible change, so every generated enum carries an Unknown(String) variant holding the value verbatim. Match the variants you care about and treat Unknown as unrecognised; it serializes back as the original string, so reading a resource and writing it again does not corrupt a field this build does not know about.

§TLS

rustls by default. For OpenSSL instead:

incident-io = { version = "1", default-features = false, features = ["native-tls"] }

Cargo features are additive across a dependency graph, so another crate asking for native-tls brings it back in alongside rustls. Pick the backend explicitly on the reqwest::Client if you need to be certain.

Turning both off is a compile error rather than a client that cannot reach the API.

Modules§

apis
models