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.
Search vs structured filters
Section titled “Search vs structured filters”A ?q= parameter is for fuzzy, free-text search across a resource (“anything matching graphql”):
GET /articles?q=graphqlStructured 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.
A consistent envelope
Section titled “A consistent envelope”Every collection response should share the same wrapper, so clients write the paging/handling code once:
The cost of total counts
Section titled “The cost of total counts”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).