Classes
RESTSource
Content source for REST APIs.
Fetches content from any REST API that returns JSON. Supports:
- Cus…
RESTSource
Content source for REST APIs.
Fetches content from any REST API that returns JSON. Supports:
- Custom headers (with environment variable expansion)
- Configurable field mappings for content and frontmatter
- Pagination (link header or cursor-based)
Configuration:
url: str - API endpoint URL (required)
headers: dict - Request headers (optional, supports ${ENV_VAR})
content_field: str - JSON path to content (default: "content")
id_field: str - JSON path to ID (default: "id")
frontmatter_fields: dict - Mapping of frontmatter keys to JSON paths
items_path: str - JSON path to items array (default: auto-detect)
pagination: dict - Pagination config (optional)
strategy: str - "link_header" or "cursor"
cursor_field: str - Field containing next cursor
ContentSourceMethods 2
fetch_all
async
Fetch all content from the API.
Handles pagination automatically if configured.
fetch_all
async async def fetch_all(self) -> AsyncIterator[ContentEntry]
Fetch all content from the API.
Handles pagination automatically if configured.
Returns
AsyncIterator[ContentEntry]
fetch_one
async
Fetch a single item by ID.
fetch_one
async async def fetch_one(self, id: str) -> ContentEntry | None
Fetch a single item by ID.
Parameters 1
id |
str |
Item identifier |
Returns
ContentEntry if found, None otherwiseContentEntry | None
—
Internal Methods 5
__init__
Initialize REST source.
__init__
def __init__(self, name: str, config: dict[str, Any]) -> None
Initialize REST source.
Parameters 2
name |
str |
Source name |
config |
dict[str, Any] |
Configuration with 'url' required |
_extract_items
Extract items array from response.
_extract_items
def _extract_items(self, data: Any) -> list[dict[str, Any]]
Extract items array from response.
Parameters 1
data |
Any |
JSON response data |
Returns
List of item dictionarieslist[dict[str, Any]]
—
_item_to_entry
Convert API item to ContentEntry.
_item_to_entry
def _item_to_entry(self, item: dict[str, Any]) -> ContentEntry | None
Convert API item to ContentEntry.
Parameters 1
item |
dict[str, Any] |
Item dictionary from API |
Returns
ContentEntry or None if content missingContentEntry | None
—
_get_nested
Get nested value by dot-separated path.
_get_nested
def _get_nested(self, obj: Any, path: str) -> Any
Get nested value by dot-separated path.
Parameters 2
obj |
Any |
Object to traverse |
path |
str |
Dot-separated path (e.g., "data.items.0.name") |
Returns
Value at path or NoneAny
—
_get_next_url
Extract next page URL from response.
_get_next_url
def _get_next_url(self, data: dict[str, Any], response: aiohttp.ClientResponse) -> str | None
Extract next page URL from response.
Parameters 2
data |
dict[str, Any] |
Response JSON |
response |
aiohttp.ClientResponse |
aiohttp response object |
Returns
Next page URL or Nonestr | None
—