Skip to main content

Spring Boot Prompt for REST Pagination & Filtering

Build advanced Spring Data REST APIs — dynamic filtering, sorting, cursor-based pagination, and HATEOAS responses with OpenAPI docs.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Build an advanced REST API layer for a Spring Boot 3.3 application with complex querying needs. Entities: Product, Order, Customer, Review. Include: 1) Spring Data JPA Specifications for dynamic filtering: equals, contains, between, in, isNull, greaterThan, lessThan, 2) Cursor-based pagination (keyset pagination) for activity feed, notifications, audit log — better than offset for large datasets, 3) Offset pagination with configurable page size and total count for products, customers, orders, 4) Multi-field sorting with direction (ASC/DESC) and null handling, 5) Full-text search using Hibernate Search with Lucene for product name, description, category, tags, 6) HATEOAS response format with HAL links using Spring HATEOAS, 7) Field projection — allow clients to request specific fields via ?fields=, 8) Nested resource expansion via ?expand= parameter, 9) ETag and conditional request support (If-None-Match, 304), 10) OpenAPI documentation for all query parameters. Include reusable base classes and integration tests.

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

Frequently Asked Questions

When should I use keyset pagination instead of offset?
Use keyset (cursor) pagination for large, append-style datasets like feeds and logs, which you assign via `[cursor_entities]`. Offset pagination scans and skips rows, so deep pages on big tables get slow, while keyset stays fast regardless of page depth.
Does it support flexible filtering without writing custom queries each time?
Yes. It uses Spring Data JPA Specifications to compose the `[filter_types]` you define dynamically. Reusable Specification classes mean new filters and entities reuse the same machinery instead of each endpoint hand-writing query logic.
How does the full-text search work?
It uses the `[search_approach]` you specify, such as Hibernate Search with Lucene, over the fields in `[searchable_fields]`. For good performance, ensure those fields are properly indexed, since search speed depends on the index, not just the API layer.
Can clients request only specific fields?
Yes. The prompt includes field projection via a `?fields=` parameter and nested resource expansion via `?expand=`. This lets clients trim responses to what they need, reducing payload size, and the OpenAPI docs describe these parameters for discoverability.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Java & Spring Boot Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support