Skip to content

Reading state views

A State View is state computed from events: a component’s evolve function folds the events its definition selects. Reading one renders it at a revision. See State Changes & State Views.

The examples use the TodoMVC example in a database of your own. Set it up first.

  • A State View and its version, such as todo-list and v1.
  • A revision: a number, or latest. latest redirects to the database’s current revision.
  • A binding for each parameter the view’s definition declares.
Terminal window
curl -L "https://sandbox.evidentsource.com/api/v1/db/todomvc-yourname/latest/state-views/todo-list/v1"
{"todos":[{"id":"3f0b5a0e-1c2d-4e5f-8a9b-0c1d2e3f4a5b","title":"Try EvidentSource","completed":false,"createdAt":"2026-09-17T00:00:00Z"}]}

The reply is the view’s state, in the content type its definition declares: here, JSON. A view whose definition names a presenter is answered by that presenter instead. A view whose state is a collection is read only through a presenter: without one, a read is refused with 409.

A view can select events by a value the reader supplies. single-todo selects the events whose subject is one todo’s id, so a read binds it:

Terminal window
curl -L "https://sandbox.evidentsource.com/api/v1/db/todomvc-yourname/latest/state-views/single-todo/v1?subject.todo_id=3f0b5a0e-1c2d-4e5f-8a9b-0c1d2e3f4a5b"

A binding is {attribute}.{parameter}={value}, where the attribute is stream, subject or event_type. Each set of bindings is its own instance of the view: one todo, one account, one order.

A read at an earlier revision shows the view as it stood then. Use a revision number in place of latest:

Terminal window
curl "https://sandbox.evidentsource.com/api/v1/db/todomvc-yourname/1/state-views/todo-list/v1"

A view whose definition folds in effective-time order is read at an effective-time cut, effective_time_end_at: a time, or now, which redirects to the time it resolved to. Such a view refuses a read without one. TodoMVC’s views fold in revision order, so they take no cut, and ignore one. See Bi-temporal reads.

Call FetchStateViewAtRevision; see gRPC API. Each SDK wraps it; see Connecting with an SDK.

There is no subscription to a State View. SubscribeDatabaseUpdates streams a database’s revision as it advances; render the view again at the revision it reports.