liveBook · Manning

Similarity search

As explained in The Design of Web APIs, Second Edition

A search operation is an API operation that retrieves resources matching supplied search criteria.

A search operation is an API operation that retrieves resources matching supplied criteria. It usually succeeds whether matching resources exist or not, returning found elements or an empty list rather than treating no results as an error. section 3.4.5 section 4.6.4

Design the operation around the consumer’s use case. A product search can return a focused ProductSummary model instead of every Product property, while exposing the product reference for later detail retrieval. section 5.3.2 section 10.1.4

Shape a useful search operation by deciding:

  • Which filters consumers need, and where they appear; for example, use keywords and category query parameters in GET /products?keywords=anime,fantasy&category=BD. section 5.3.2
  • How to sort and paginate large collections, reducing transferred data and avoiding impractical requests for every element. section 9.6
  • Which HTTP responses represent results; 200 OK can represent both matching products and an empty result list. section 4.5.6
  • Whether sensitive or overly complete filters require POST /resources/search instead of GET /resources; such operations should not also define query parameters. section 18.13

Searching a product catalog

GET /products?keywords=anime,fantasy&category=BD returns an array of ProductSummary objects. A matching response contains productReference, name, category, keywords, and price; no matches produce the same successful response shape with an empty array. Consumers can request full details through GET /products/{productReference}. section 5.3.2 section 4.6.4

Figure 9.9 Enabling filtering, sorting, and paginating lists is essential to allow consumers to get only the elements they want, sorted as needed.
figure

Use filtering, sorting, and pagination together to let consumers retrieve only the collection elements they need, in the order and page they choose. section 9.6

How The Design of Web APIs, Second Edition covers it

How deep it goes
Defines inputs, representations, statuses, empty results, and collection controls, but does not detail implementation internals.
Examples
Uses product catalogs, bank transactions, rental cars, ProductSummary responses, and GET or POST search paths.
What you can do after
Build it from scratch by specifying search paths, parameters, representations, statuses, empty-result behavior, and collection controls.
How it connects
Connects collection resources with filtering, sorting, pagination, HTTP GET, response modeling, and error handling.

Also explained in

Compare how 22 books explain similarity search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.