liveBook · Manning

Unstructured filter representation

As explained in API Design Patterns

An unstructured filter representation encodes filtering criteria as text that conforms to a syntax interpreted by the API server.

An unstructured filter representation encodes filtering criteria as a string whose syntax the API server interprets. It keeps the API familiar to users and avoids forcing them to learn a custom filter structure. section 22.3.1

Prefer a string field when filter requirements may evolve. Custom structured interfaces tend to create brittleness and a steeper learning curve without clear benefits over serialized strings. section 22.3.1

ChatRoom filtering

A ChatRoom filter can use a SQL-like expression such as `title = "New Chat!"`; a structured alternative represents the same criterion as `{ title: "New Chat!" }`. section 22.3.1

Table 22.1 SQL string queries versus MongoDB filter structures (view table figure)

SQL query

MongoDB filter

title = "New Chat!"
{ title: "New Chat!" }
userLimit >= 5
{ userLimit: { $gt: 5 } }
title = "New Chat!"
AND
admin = "1234"
{ title: "New Chat!", admin: "1234" }
title IN ("New Chat!", "Old Chat!")
{ title: { $in: [
    "New Chat!",
    "Old Chat!"
] } }
title = "New Chat!"
OR
title = "Old Chat!"
{ $or: [
    { title: "New Chat!" },
    { title: "Old Chat!" }
] }
(title = "new chat!"
AND userLimit >= 5)
OR
title = "old chat!"
{ $or: [
    { title: "New Chat!",
      userLimit: { $gt: 5 } },
    { title: "Old Chat!" }
] }

Compare equivalent equality, comparison, conjunction, membership, disjunction, and grouped filters across string queries and structured filters. section 22.3.1

How API Design Patterns covers it

How deep it goes
Explains representation trade-offs and points toward filter syntax without specifying a complete grammar.
Examples
Uses ChatRoom equality filters and compares SQL string queries with MongoDB filter structures.
What you can do after
Apply it by choosing a string field when familiarity and long-term API extensibility outweigh custom structure.
How it connects
Connects filtering with API evolution, structured interfaces, serialized strings, SQL queries, and MongoDB filter structures.

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.