View Models
View models provide a presentation layer on top of your content, allowing you to transform, compute, and aggregate data before returning it through the GCA. Unlike content models which expose raw content data, view models (classes extending ViewModel<M> with @ViewInterface) enable you to create computed fields, combine data from multiple sources, accept request parameters, and tailor responses to specific front-end requirements without modifying your underlying content types.
The GCA supports two ways to access view models:
Content-backed view models — accessed via the Get operation's View field when you have a content identifier. Ideal for transforming specific content items for presentation, with full support for editorial features like preview.
Standalone view models — backed by the endpoint itself and accessed via the root View field without requiring a content ID. Ideal for computed data like navigation menus, site configurations, or aggregated statistics.
Both access patterns produce the same kind of view types in the schema, detailed in the ViewModel Schema Types reference.
The examples in this section build on this configuration:
191015@Override16protected GCASchemaSettings getSchemaSettings() {17return GCASchemaSettings.newBuilder()18.readonlyEntryClass(Article.class)19.entryViewClass(ArticleViewModel.class)20.endpointViewType(OperationType.QUERY, NavigationViewModel.class)21.build();22}23}
If you're deciding between exposing content models directly versus through view models, see the discussion in Getting Started. In short: content models are great for ingestion, migration, and internal tools; view models give you a stable, curated contract for public content delivery with business logic centralized on the server.