Queries
A screen needs a list, a detail view, or a dashboard—not another hand-written API client. Arc lets you declare the read, expose it through HTTP, and generate a typed TypeScript proxy for the frontend.
Queries read application state. That can be a MongoDB document, an EF Core entity, data from a service, or an in-memory model. Arc queries do not require Chronicle or event sourcing. A database query or MongoDB Observe() call is not a Chronicle projection. If your application optionally uses Chronicle, its projected read models can be queried too; see Chronicle integration.
Choose a declaration style
Section titled “Choose a declaration style”| Style | What you write | Choose it when |
|---|---|---|
| Model-bound | Static query method on the [ReadModel] type it returns | You want the query next to its data shape with minimal endpoint boilerplate |
| Controller-based | MVC GET action | You need MVC route-value/DTO binding, filters, or HTTP response control |
The two paths share result rendering but not all binding, validation, or authorization behavior. Start with the model-bound example, then use the controller path deliberately where its contract fits better.
Request once or observe updates
Section titled “Request once or observe updates”| Mode | Behavior | Use it for |
|---|---|---|
| Request/response | Read once through GET or generated HTTP QUERY | One-off reads and reports |
| Observable | Subscribe to a producer over SSE/WebSocket | Lists or dashboards that should stay current |
An observable query needs a producer that detects changes; a return type alone does not watch your database. Arc’s MongoDB integration supplies Observe(). Other providers need their own observation mechanism. An update may follow a command changing database state directly, or an optional Chronicle projection updating it.
Learn the contract in order
Section titled “Learn the contract in order”- Declare a model-bound read, then add arguments.
- Apply validation and authorization, including their current limitations.
- Read the QueryResult contract and add paging.
- Expose observable updates and understand subscription disposal.
- For advanced delivery, use the hub protocol, change streams, and emission guards.
Read-model interception transforms supported result paths, but currently excludes observable HTTP snapshots. Query health helps diagnose hub subscriptions but exposes sensitive telemetry unless you restrict it. Use cURL workflows to distinguish a snapshot from a live stream.
Consume the read in React
Section titled “Consume the read in React”A successful backend proxy-generation build supplies typed client declarations. Use the generated query’s hook and result state instead of maintaining a separate transport model. Continue with queries in React and proxy generation.