Skip to content

Container ​

container is the central dependency-injection mechanism that your app creates. It holds references to every resource: configurations, auth keys, data sources, logging, metrics, and external HTTP services.

Overview ​

Access Workflow ​

The context holds a reference to the container. Through it, the context reaches every resource and runs the operations each incoming request needs.

PubSub covers Kafka, MQTT, and NATS. KVStore (Redis / NATS KV / memory / SQLite) and FileStore (local / ftp / sftp) are the unified key-value and blob backends. Register them with app.addKVStore(...) and app.addFileStore(...) (see KV Store) and File Store)).

Health checks ​

The container aggregates component health behind two well-known endpoints:

  • GET /.well-known/health: returns the aggregated status as JSON ({ "<name>": "up" }). If any check fails the response body reports the failing component as down and the endpoint returns a non-200 status.

  • GET /.well-known/live: liveness probe, always returns 200 (the process is up).

Two probes are registered automatically when the corresponding datasource is configured:

  • sql: acquires and releases a pooled connection (Postgres); SQLite is reported healthy once loaded.
  • redis: a PING round-trip.

Register your own check with app.addHealthCheck:

zig
try app.addHealthCheck("my-dep", myDepCheck);

fn myDepCheck(c: *zero.container) anyerror!void {
    // return normally when healthy; any error marks the component "down"
    if (!try c.myDep.ping()) return error.Unhealthy;
}

The handler receives the *container, so it can reach any registered resource (c.SQL, c.kv, c.pubsub, …) to validate it.