An inventory screen needs to show active products that are low on stock or backordered. It also needs a total count and a stable sort order. I’d give the API a shared vocabulary for filters and pagination, then let each endpoint define the fields callers can use and the records they can see.
Give each filter three parts
A filter has a field, an operator, and a value. For example, {"field":"stock","op":"lt","value":10} asks for products with fewer than ten units in stock. An inventory endpoint can allow numeric comparisons on stock and text matching on names. Each endpoint maps its public fields to SQL expressions, so a field like color can live inside a JSON column without changing the request shape.
The query builder picks the SQL expression and comparison from those predefined mappings. It passes the value as a SQL parameter.
Keep access rules outside the filter
In a multi-store catalog, the server determines which store the caller can see. The generated predicate should have this shape:
WHERE store_id = @store_id
AND status = @status
AND (stock < @threshold OR backordered = @backordered)The parentheses keep the two alternatives inside the store’s scope. I’d test this with a backordered product in another store and assert that it stays out of both the results and the total.
Make the page and count agree
Use the same predicates for the page query and the count query. If two products share a name, add the product ID as a tie-breaker so their order is deterministic for a given dataset. A good pagination test requests one item per page and checks that each page reports the same matching total.
The shared contract stays small. The endpoint still owns field mappings, access rules, and the database query.