Search API Design
You'll learn to
- -Design a search endpoint that supports full-text query, faceted filtering, and result highlighting together
- -Distinguish search-endpoint design from the plain filtering covered earlier in this course
Simple filtering (`?status=shipped`) and real search are different problems - search implies ranking by relevance, not just matching a boolean condition, and a well-designed search endpoint needs to expose that ranking behavior alongside the filters a client also wants to combine with it.
Combining Full-Text Query With Facets
GET /products/search?q=wireless+headphones&category=electronics&price_max=200&sort=relevanceThe `q` parameter carries the free-text query (matched by relevance ranking, not exact equality), while `category` and `price_max` are ordinary structured filters, narrowing the searchable set before or alongside ranking. Both can compose in the same request, and `sort=relevance` (the default for a search endpoint, unlike a plain listing endpoint which usually defaults to something like creation date) makes explicit that results are ranked, not just filtered.
Faceted Results
{
"results": [ /* matching products */ ],
"facets": {
"category": [{"value": "electronics", "count": 340}, {"value": "accessories", "count": 89}],
"brand": [{"value": "Sony", "count": 52}, {"value": "Bose", "count": 41}]
},
"total_results": 429
}Facets let a client build a filter sidebar without a separate request per possible filter value - the search response itself reports which categories, brands, or other dimensions actually appear (and how often) within the current result set, so the client can render "Electronics (340)" as a clickable refinement, computed against the live results rather than the whole catalog.
Highlighting Matched Terms
{
"id": 501,
"name": "Sony Wireless Noise-Cancelling <em>Headphones</em>",
"highlight": {"description": "...premium <em>wireless</em> audio experience..."}
}Highlighting wraps the matched query terms within the result (commonly with `<em>` tags or a similar marker) so a client can visually show the user why a given result matched, which matters most for fuzzy or partial matches where the connection between query and result isn't immediately obvious from the plain title alone.
A search endpoint is a natural candidate to be its own dedicated endpoint (`/products/search`) rather than overloading the plain collection endpoint (`/products?q=...`) - it signals to clients (and to caching/rate-limiting infrastructure) that this specific endpoint has different performance characteristics and semantics than a plain filtered listing.
Interview Signal is part of Pro
See a real weak answer next to a real strong one for this exact topic.
Quiz is part of Pro
Test what you just read with a short quiz, and bank the XP.
Design Search Engine API in the API Design Lab's Production Patterns act.