What this prompt does
This prompt builds an advanced REST query layer for a Spring Boot [spring_version] application over the entities you list in [entities]. It implements JPA Specifications for dynamic filtering ([filter_types]), cursor-based keyset pagination for [cursor_entities], offset pagination for [offset_entities], multi-field sorting, full-text search via [search_approach] over [searchable_fields], HATEOAS responses, field projection via ?fields=, nested expansion via ?expand=, ETag and conditional-request support, and OpenAPI documentation — plus reusable base classes and integration tests.
The structure works because APIs that feel fine on small data quietly fall apart as tables grow. The key distinction the prompt forces is keyset pagination for [cursor_entities] versus offset for [offset_entities]: offset pagination scans and skips rows, so deep pages on large tables get slow, while keyset stays fast. Pairing reusable Specification-based filtering with that pagination choice is what keeps the API responsive rather than timing out under load.
When to use it
- When an API must stay fast as
[entities]grow into large datasets - When deep pagination over feeds or logs (
[cursor_entities]) is slowing down - When clients need flexible dynamic filtering across many
[filter_types] - When you want full-text search over
[searchable_fields]without bolting on a separate service prematurely - When API consumers benefit from HATEOAS links and field projection
- When you need conditional requests (ETag, 304) to cut redundant payloads
- When consumers want field projection and nested expansion to trim response payloads to exactly what they use
Example output
Expect a Spring Boot implementation: reusable Specification classes covering [filter_types], keyset pagination for [cursor_entities] and offset pagination with total count for [offset_entities], multi-field sorting with direction and null handling, full-text search via [search_approach] over [searchable_fields], HATEOAS HAL responses with links, field projection via ?fields= and nested expansion via ?expand=, ETag and conditional-request support returning 304s, and OpenAPI parameter docs, with integration tests across your [entities]. It centers on reusable base classes that new entities inherit rather than one-off controller code, so the filtering and pagination machinery is written once and shared.
Pro tips
- Route high-volume, append-style data in
[cursor_entities]to keyset pagination; offset pagination degrades on deep pages of large tables - Keep
[filter_types]to the operators you actually need so the Specification layer stays maintainable rather than a sprawling query DSL - Confirm
[searchable_fields]are indexed appropriately for your[search_approach], or full-text search will be slow regardless of the API design - Use the reusable base classes so new
[entities]inherit filtering and pagination instead of each controller reimplementing it - Enable ETag and conditional requests for read-heavy endpoints to save bandwidth on unchanged responses
- Document every query parameter in OpenAPI so consumers can discover filtering and expansion without reading the source