
Sanity Has a Free API — Here's How to Use GROQ to Query Your Content
Sanity is a structured content platform with a powerful query language called GROQ. The free tier includes generous API usage — 500K API requests/month and 20GB bandwidth. Setting Up npm create sanity@latest -- --project-id your-id --dataset production Get your project ID and dataset from manage.sanity.io . Querying with GROQ GROQ (Graph-Relational Object Queries) is Sanity's query language — more powerful than REST, simpler than GraphQL. import { createClient } from " @sanity/client " ; const client = createClient ({ projectId : " your-project-id " , dataset : " production " , apiVersion : " 2024-01-01 " , useCdn : true }); // Get all blog posts, ordered by date const posts = await client . fetch ( `*[_type == "post"] | order(publishedAt desc) { title, slug, publishedAt, "authorName": author->name, "categories": categories[]->title, "imageUrl": mainImage.asset->url }` ); posts . forEach ( p => console . log ( ` ${ p . title } by ${ p . authorName } ` )); Advanced GROQ Queries // Count
Continue reading on Dev.to Webdev
Opens in a new tab

