RFC 008: API Filtering
This RFC proposes a consistent approach to filtering and sorting resources in our APIs, ensuring a uniform developer experience.
Last modified: 2019-09-24T13:00:32+01:00
Problem statement
To ensure a consistent developer experience across our APIs, we need to agree a set of patterns for filtering and sorting. This document outlines our approach.
Suggested solution
There are three complementary parts to this:
structured filtering
full text querying
sorting
Structured filtering
Structured filters are non-scoring (ie, they do not result in relevance scores) queries that can be used to restrict the resources returned, without influencing the order in which they are returned.
Structured filters have the following characteristics:
They are supplied as query parameters
They have the name of the property they are used filter
Multiple query parameters are combined using
ANDMultiple comma (
,) separated values within a single query parameter are combined usingORClosed-open ranges are supported using
/Dotted syntax is used to specify paths
idis implicit in parameter paths
Examples:
Filter for a single work type:
/works?workType=bookFilter for multiple work types:
/works?workType=book,ebookFilter for multiple work types with a single subject:
/works?workType=book,ebook&subjects.concepts={id}Filter for multiple work types with a multiple co-occurring subjects:
/works?workType=book,ebook&subjects.concepts={subjectID1}&subjects.concepts={subjectID2}Searching within structured data within structured filtering
Full text querying
Full text querying is supported as a scoring query that can be used to restrict the resources returned, by default returning them in relevance order.
Full text querying has the following characteristics:
It is supplied as a single query parameter
The query parameter is called
queryIt can be combined with any combination of structured filters
Some field based and other advanced full text querying may be supported, but is service dependent
Examples:
Find all works that mention skeletons:
/works?query=skeletonsFind all works that mention skeletons and are books or ebooks:
/works?query=skeletons&workType=book,ebookSorting
The default ordering for a collection of resources is service dependent. It can also vary for different kinds of resource within the same service, to ensure that the default ordering is the most appropriate in the majority of cases.
In addition to this:
Use of full text querying should change the default order to ordering by relevance
This can be overridden using a
sortparameterThe value of this parameter is a comma separated list of properties
The order within a property can be changed using
ascanddescmodifiers
Example:
/works?query=skeletons&sort=year desc,titleLast updated