Live poll
One poll, shared by everyone who visits. The count lives on the server; each vote is broadcast to all open windows.
Loading the poll
ConnectingHow it works
Clients never send votes to each other. A vote is a normal request to the backend, which updates its count
and publishes the full result to the poll channel. Every browser replaces what it shows with
what it receives, so nobody can drift out of sync.
A window that opens later fetches the current result once over HTTP, then follows the channel. That pair, fetch then subscribe, is the pattern for any server-owned state: scores, stock levels, job progress.
You can change your answer: the browser sends your previous choice along and the server moves the vote. This demo trusts the browser about that. A real poll would keep track of who voted on the server.
async fn vote(State(app): State<App>, Json(vote): Json<Vote>) -> Json<Results> {
let results = app.poll.add(&vote.option);
// POST https://api.pikoman.se/poll/results
app.pikoman.publish("poll", "results", &results).await;
Json(results)
}