summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-26 05:27:19 +0100
committertv <tv@krebsco.de>2026-10-26 05:27:19 +0100
commitf9955f3a5afcb82a591e7f434c20fa224878c009 (patch)
tree48ff81a039f82e0151543eae5f5f0e4e9a467079 /src
parentca5fbf8736aef1c754f5048cc21bacb2f91360e2 (diff)
add GET /stream endpoint
Diffstat (limited to 'src')
-rw-r--r--src/api/mod.rs1
-rw-r--r--src/api/store.rs18
2 files changed, 17 insertions, 2 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs
index 8f271f4..296fa5e 100644
--- a/src/api/mod.rs
+++ b/src/api/mod.rs
@@ -41,6 +41,7 @@ pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) ->
.put(store::put_store_entry)
.delete(store::delete_store_entry),
)
+ .route("/stream", get(store::stream_store_root))
.route("/stream/{*key}", get(store::stream_store_entry))
.route("/peers", get(peers::list_peers))
.route("/peers/{peer}", delete(peers::delete_peer))
diff --git a/src/api/store.rs b/src/api/store.rs
index aa9465c..c8a072f 100644
--- a/src/api/store.rs
+++ b/src/api/store.rs
@@ -303,16 +303,30 @@ async fn render_traced(
.await
}
+/// `GET /stream`: follows the whole store, as `GET /store` reads it (events have an
+/// empty `key`).
+pub(crate) async fn stream_store_root(
+ State(state): State<AppState>,
+) -> Result<Response, StatusCode> {
+ stream(state, String::new(), Vec::new()).await
+}
+
+/// `GET /stream/{key}`: follows one value.
pub(crate) async fn stream_store_entry(
State(state): State<AppState>,
Path(key): Path<String>,
) -> Result<Response, StatusCode> {
+ let path = parse_key_path(&key)?;
+ stream(state, key, path).await
+}
+
+/// Newline-delimited JSON events for the value at `path` (`key` as the client wrote it):
+/// the current value, then one whenever the resolved value changes.
+async fn stream(state: AppState, key: String, path: Vec<String>) -> Result<Response, StatusCode> {
if !state.is_ready().await {
return Err(StatusCode::SERVICE_UNAVAILABLE);
}
- let path = parse_key_path(&key)?;
-
// Subscribe first, so nothing between the initial read and the loop is missed.
let mut changes = state.change_events.subscribe();