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.

Füllen Sie die Platzhalter aus

Edit the values, then copy your finished prompt.

Ihr Prompt
prompt.txt

                                

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.

Mehr in Java & Spring Boot Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

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

[email protected]

✓ 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