pub struct ReadinessResponse {
pub status: HealthStatus,
pub version: String,
pub service_id: String,
pub checks: HashMap<String, Vec<HealthCheck>>,
}Expand description
Readiness/startup probe response (GET /health/ready, GET /health/startup) — RFC 8458.
Answers the question: “is this service ready to handle traffic?” Includes dependency checks (database, cache, upstream services).
HTTP status: 200 OK on pass/warn, 503 Service Unavailable on fail.
Requires the std feature (uses HashMap for dependency checks).
Fields§
§status: HealthStatusOverall health status, derived from the worst check result.
version: StringSemantic version of the service, e.g. "1.0.0".
service_id: StringUnique identifier for this service instance, e.g. "my-service".
checks: HashMap<String, Vec<HealthCheck>>Component check results. Key format: "<component>:<measurement>".
Example: "postgres:connection", "redis:latency".
Implementations§
Source§impl ReadinessResponse
impl ReadinessResponse
Sourcepub fn new(
version: impl Into<String>,
service_id: impl Into<String>,
checks: HashMap<String, Vec<HealthCheck>>,
) -> Self
pub fn new( version: impl Into<String>, service_id: impl Into<String>, checks: HashMap<String, Vec<HealthCheck>>, ) -> Self
Create a new readiness response, computing overall status from checks.
Status is the worst of all check statuses: fail > warn > pass.
§Examples
use std::collections::HashMap;
use api_bones::health::{ReadinessResponse, HealthCheck, HealthStatus};
let mut checks = HashMap::new();
checks.insert(
"postgres:connection".to_string(),
vec![HealthCheck::pass("datastore")],
);
checks.insert(
"redis:ping".to_string(),
vec![HealthCheck::fail("datastore", "timeout")],
);
let resp = ReadinessResponse::new("1.0.0", "my-service", checks);
assert_eq!(resp.status, HealthStatus::Fail);
assert_eq!(resp.http_status(), 503);Sourcepub fn http_status(&self) -> u16
pub fn http_status(&self) -> u16
HTTP status code for this response.
Sourcepub fn builder() -> ReadinessResponseBuilder<(), ()>
pub fn builder() -> ReadinessResponseBuilder<(), ()>
Return a typed builder for constructing a ReadinessResponse.
Required fields (version and service_id) must be set before calling
ReadinessResponseBuilder::build; the compiler enforces this via typestate.
Use ReadinessResponseBuilder::add_check to accumulate component checks.
§Example
use api_bones::health::{HealthCheck, ReadinessResponse};
let resp = ReadinessResponse::builder()
.version("1.0.0")
.service_id("my-service")
.add_check("postgres:connection", HealthCheck::pass("datastore"))
.build();
assert!(resp.checks.contains_key("postgres:connection"));Trait Implementations§
Source§impl Clone for ReadinessResponse
impl Clone for ReadinessResponse
Source§fn clone(&self) -> ReadinessResponse
fn clone(&self) -> ReadinessResponse
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more