Documentation
¶
Overview ¶
Package api implements the v1.3+ REST API. Routes mount under /api/v1. The API is JSON-only, returns a consistent error envelope {"error":"..."} on every non-2xx, supports pagination via ?page + ?per_page query params, and emits ETag headers for cacheable read endpoints so well-behaved clients (and the v1.4 studio UI) skip re-rendering identical responses.
Auth: every route is gated on either a session cookie (browser flows) or a Bearer token with the right scope (machine flows). The Mount() function wires both middlewares; downstream handlers resolve the actor via auth.TokenFromContext + auth.FromContext.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is the surface the daemon mounts onto its chi router. Holds references to the persistence + auth dependencies the handlers need.
func New ¶
New constructs the API handle. The Mount() method wires every route on r under the /api/v1 prefix.
func (*API) Mount ¶
Mount installs the v1 routes on r. Phase 6 ships the read surface; phase 7 layers the write endpoints on this same prefix. Phase 11 (UI shell) calls Mount before starting the server.
func (*API) WithCache ¶ added in v1.11.0
WithCache installs the v1.11 phase 6 LRU response cache. Returns the receiver for chaining. When set, hot list responses are served from cache (60s TTL, busted on SSE mutation events). Nil/unset means every request hits the DB — the v1.10 default.
func (*API) WithEvents ¶ added in v1.6.0
WithEvents installs the v1.6 SSE Producer. Returns the receiver for chaining. When set, the /api/v1/events route is mounted; otherwise it 404s and the daemon's polling paths still work.
func (*API) WithPush ¶ added in v1.16.0
WithPush installs the v1.16 phase 4 Web Push store + sender. Returns the receiver for chaining. When set, /api/v1/push/* endpoints mount + critical-finding events fan out to subscribed devices. Nil/unset means push endpoints 503 and no push fires.
func (*API) WithSearch ¶ added in v1.19.0
WithSearch installs the v1.19 phase 5 global search index. Returns the receiver for chaining. When set, GET /api/v1/search serves the index; otherwise it 503s. Nil/unset is safe — the daemon's v1.5 Cmd+K palette still works against its own endpoints.
type Cursor ¶ added in v1.11.0
type Cursor struct {
SortKey string `json:"k"` // RFC3339 timestamp or other monotonic key
ID string `json:"i"`
}
Cursor is the opaque pagination token. SortKey + ID together form the (last-row-of-previous-page) tuple; the next query selects rows strictly after this pair under the documented sort order.