liveBook · Manning

Filtering

As explained in API Design Patterns

Filtering is the selection of items that satisfy specified conditions before results are returned or processed.

Filtering selects only resources matching stated conditions before an API returns or processes them. Server-side filtering avoids fetching and evaluating an entire collection on the client, reducing network and processing waste. section 22.1 section 22.2

Use filtering deliberately in standard list methods:

  • Add a filter field to the list request and evaluate it before returning results. section 22.3.3
  • Represent the filter as a string following documented syntax rather than a rigid client-side schema, preserving room for future extensions. section 7.3.4 section 22.3.1
  • Keep evaluation scoped to a single resource, reject positional comparisons in repeated fields, and surface evaluation errors immediately. section 22.6
  • Document only useful operations, adding functions when basic comparisons cannot express required intent instead of opening unrestricted query behavior. section 22.2 section 22.6

Filtering a chat-room list

A list endpoint can accept a request such as { filter: "title = \"New Chat!\"" } and return only matching ChatRoom resources. The same intent can be expressed with a structured MongoDB-style query, but a string keeps the public request shape less coupled to an evolving schema. section 22.3.1 section 23.3.8

Filtering also supports operational workflows: listing operations can find unfinished or paused work and query operation metadata. Export methods can filter resources before serialization, while keeping selection separate from output configuration. section 10.3.8 section 23.3.8

Listing 22.8 Final API definition
abstract class ChatRoomApi {
  @get("/chatRooms")
  ListChatRooms(req: ListChatRoomsRequest): ListChatRoomsResponse;
}
 
interface ListChatRoomsRequest {
  filter: string;
  maxPageSize: number;
  pageToken: string;
}
 
interface ListChatRoomsResponse {
  results: ChatRoom[];
  nextPageToken: string;
}

Inspect the compact list-request definition showing filter alongside pagination fields and the paginated response. section 22.3.3

How API Design Patterns covers it

How deep it goes
Explains request design, representation trade-offs, evaluation boundaries, errors, and supported functions, while excluding unrestricted cross-resource queries.
Examples
Uses ChatRoom title predicates, SQL and MongoDB equivalents, client-side pagination, operation metadata, and filtered exports.
What it assumes
Builds on standard list methods and resource fields, while defining filter representation and evaluation rules explicitly.
What you can do after
Apply it via standard list and export requests to reduce transferred data and inspect targeted resource subsets.
How it connects
Connects standard list methods with pagination, long-running operations, export methods, field masks, SQL queries, and structured queries.

Also explained in

Compare how 33 books explain filtering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.