Feature: Generic Data API
A key architectural feature of the API server is its generic data endpoint, located at /api/v1/data
. Instead of having separate endpoints for each data type (e.g., /headlines
, /topics
), this single, powerful endpoint can manage multiple data models through a simple query parameter.
This approach simplifies the API surface, reduces code duplication, and makes the system highly extensible.
How It Works
Section titled “How It Works”A client makes a standard REST request (GET, POST, PUT, DELETE) to the /api/v1/data
endpoint and specifies the target data type using the ?model=
query parameter.
Example: Fetching all headlines
GET /api/v1/data?model=headline
Example: Fetching a single topic by its ID
GET /api/v1/data/some-topic-id?model=topic
Example: Fetching countries by usage
GET /api/v1/data?model=country&filter={"usage":"eventCountry"}
This fetches countries that are referenced as ‘event countries’ in headlines. Similarly, filter={"usage":"headquarters"}
can be used to fetch countries that are headquarters for sources.
Example: Fetching countries by name
GET /api/v1/data?model=country&filter={"name":"United"}
This fetches countries whose names contain “United”, supporting partial and case-insensitive matches.
The Dual Registry System
Section titled “The Dual Registry System”The power behind this generic endpoint comes from two central registries:
-
The Model Registry (
ModelRegistry
): This registry defines the rules for each model. It maps a model name (e.g.,"headline"
) to a configuration object that specifies authorization requirements, ownership details, and how to handle JSON data for that model. -
The Data Operation Registry (
DataOperationRegistry
): This registry provides the actions. It maps a model name to the actual functions that perform the CRUD operations (Create, Read, Update, Delete).
Supported Models
Section titled “Supported Models”The generic data endpoint can manage the following models out-of-the-box:
headline
topic
source
country
language
user
user_app_settings
user_content_preferences
remote_config
dashboard_summary