response-layout

Implements layout query parameter support for Spring Boot REST endpoints using the Strategy and Registry pattern.

Updated Jun 25, 2026
One-click install
npx skills add https://github.com/oriddd/ai-toolkit --skill response-layout-oriddd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: response-layout
Source: https://github.com/oriddd/ai-toolkit/tree/main/copilot/public/skills/response-layout
Command: npx skills add https://github.com/oriddd/ai-toolkit --skill response-layout-oriddd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? REST endpoints often need to return different field sets depending on the client — a mobile app may want a compact summary while a web dashboard needs full data. Hardcoding separate endpoints or bloating a single DTO leads to duplicated code and wasted bandwidth. ## Core Features & Use Cases - Layout-based DTO mapping: Clients request ?layout=summary, detailed, or full, and a LayoutHandler resolves the type, routes through a registry, and returns the tailored DTO. - Open-closed extensibility: Add a new layout by creating one new LayoutStrategy class — the handler, resolver, and registry never change. - Safe fallbacks: Unknown or missing layout parameters fall back to the mandatory DETAILED layout, with a warning log when no matching strategy exists. - Use Case: A product API serves a mobile app (summary fields only), a web UI (standard detail view), and an admin console (full data including expensive computed metadata) — all from one endpoint. ## Quick Start Apply the response-layout skill to add ?layout=summary/detailed/full support to my Spring Boot entity endpoint using the Strategy and Registry pattern.

Frequently Asked Questions about response-layout

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I return different response fields from one Spring Boot endpoint?

Use a layout query parameter (?layout=summary/detailed/full) resolved by a LayoutResolver, then route through a LayoutRegistry to a LayoutStrategy that maps the entity to the matching DTO. The controller passes the HttpServletRequest to a LayoutHandler and returns the resulting DTO.

How to add a new response layout without changing existing code?

Add a new value to the LayoutType enum, create the new DTO class, and implement a new LayoutStrategy annotated with @Component. Spring injects it into the registry automatically, so the handler, resolver, and existing strategies require zero changes.

When should I use layout strategies instead of @JsonView or @JsonInclude?

Use layout strategies when endpoints return substantially different field sets per client type or when layouts involve expensive computed fields. For differences of only one or two fields, Jackson's @JsonInclude or @JsonView annotations are simpler.

What happens when the layout query parameter is missing or invalid?

The LayoutType.fromString method defaults to DETAILED when the parameter is blank or unparseable. If no strategy matches a resolved type, the LayoutHandler logs a warning and falls back to the DETAILED strategy, throwing an exception only if DETAILED itself is missing.

Can layout selection use the Accept header instead of a query parameter?

Yes. The resolver is a separate component, so you can swap the query-parameter implementation for one that inspects the Accept header, such as matching application/vnd.api.summary+json, without touching the handler, registry, or strategies.