What problem does it solve?
Components in Canvas need reliable, performant access to Drupal content but fetching JSON:API data, handling related entities, and managing caching is error-prone and can produce circular references or excessive payloads. This Skill codifies patterns to fetch Drupal content safely with JsonApiClient and SWR while preserving loading, empty, and error states for real previews in Workbench.
Core Features & Use Cases
- SWR-based fetching for caching, revalidation, and a simple hook API when building components that render remote content.
- JsonApiClient + DrupalJsonApiParams patterns for constructing queries, includes, and field filters to limit payloads and avoid circular references.
- Setup gate and validation to ensure CANVAS_SITE_URL and CANVAS_JSONAPI_PREFIX are configured before attempting live JSON:API requests, with fallbacks to static content for previews.
- Use Case: Build a news listing that sorts by created date, includes category and image relationships, and limits fields to only title, created, and image URL.
Quick Start
Build a Canvas component that uses JsonApiClient and SWR to fetch a paginated list of articles from my Drupal site's JSON:API, include category and image relationships, and limit fields to only those required for the list view.