Skip to content

Search & Envelopes

Two finishing touches make collection endpoints pleasant to use: a search parameter for free-text queries, and a single envelope shape every collection shares.

A ?q= parameter is for fuzzy, free-text search across a resource (“anything matching graphql”):

GET /articles?q=graphql

Structured filters (?status=published) answer precise questions; search answers vague ones. They compose — ?q=graphql&status=published searches within a filtered set. Keep them distinct: q is ranked, fuzzy, and may be backed by a search engine; filters are exact predicates.

Every collection response should share the same wrapper, so clients write the paging/handling code once:

JavaScript

Returning total is convenient but, on large tables, counting every matching row can be as expensive as the query itself. Options: cache the count, return an approximate count, or omit it entirely (cursor pagination often does — it offers next without a grand total).

How does `?q=` differ from a structured filter like `?status=published`?
Why can returning a `total` count be expensive?
What is the benefit of one shared collection envelope?