Sanity: API Design — GROQ Queries & Mutations
Docs-backedContent reads: GET to /v{version}/data/query/{dataset}?query={GROQ} — the entire read API is one endpoint with GROQ queries. GROQ enables filtering (*[_type == 'post' && published]), projections ({title, slug, author->name}), ordering, slicing, and graph traversal. Content writes: POST to /v{version}/data/mutate/{dataset} with transaction array of create/createOrReplace/createIfNotExists/patch/delete operations. Mutations are transactional — all operations in a request succeed or fail together. Asset management: upload images and files via /assets/images/ or /assets/files/. Real-time listener: GET /v{version}/data/listen/{dataset}?query={GROQ} returns SSE stream of matching document changes. The GROQ-based read API is more flexible than REST resource endpoints but requires learning the query syntax. Mutations provide atomic multi-document operations.