02. Resources and relationships

These tutorials cover resource CRUD, relationship linkage and related-record queries. Use the same public relationship names in plain input and JSON:API relationships; backing foreign-key columns are storage details.

Each runnable scenario starts from a fresh database unless it explicitly says otherwise. Do not concatenate different chapters’ resource declarations into one API: several deliberately reuse the same resource names.

Tutorial What it demonstrates
Starting point API, database and Express setup.
Manipulating and searching tables CRUD, declared filters, custom search and sparse fields.
Belongs-to relationships Public relationship input, linkage, includes, filtering and clearing.
Has-many relationships Reverse membership, includes, related queries, attachment and removal.
Polymorphic relationships Typed identifiers, distinct resources sharing an ID, includes and search.
Many-to-many relationships Membership and ordinary pivot metadata, with canonical-storage distinctions.
Pagination and ordering Default caps, numbered/cursor pages, sorting and sparse results.
PUT and PATCH Explicit replacement, omitted-value rejection and relationship-object boundaries.
Relationship URLs Identifier linkage versus related records, and relationship mutation endpoints.

For query projections and their SQL ordering, use Query Projections. For mandatory visibility before counts and pagination, use Row Policies or Autofiltering, according to the required policy. See backend capabilities for database differences.