Skip to main content

Module server

Module server 

Source
Available on crate features sync and sync-http only.
Expand description

Server-side sync handler for HTTP consumers.

SyncServer provides framework-agnostic methods for handling sync requests. Consumers wire these into their web framework (Axum, Actix, etc.) without PulseDB taking a dependency on any web framework.

§Example (Axum)

use std::sync::Arc;
use axum::{Router, routing::{get, post}, extract::State, body::Bytes, http::StatusCode};
use pulsedb::sync::server::SyncServer;

async fn handle_health(State(server): State<Arc<SyncServer>>) -> StatusCode {
    match server.handle_health() {
        Ok(()) => StatusCode::OK,
        Err(_) => StatusCode::SERVICE_UNAVAILABLE,
    }
}

async fn handle_handshake(State(server): State<Arc<SyncServer>>, body: Bytes) -> Result<Vec<u8>, StatusCode> {
    server.handle_handshake_bytes(&body).map_err(|_| StatusCode::BAD_REQUEST)
}

Structs§

SyncServer
Server-side sync handler.