Skip to main content

Claude/ChatGPT Prompt to Build a Spring Boot 3 REST API

Generate a Spring Boot 3 REST API with Java records, Bean Validation, JPA, Flyway, OpenAPI, and Testcontainers integration tests.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt has the model act as a senior Java engineer and return complete, compilable Spring Boot 3 code with the full project structure, not isolated snippets. It assembles the pieces a real REST API needs together — validated DTOs, a global exception handler, JPA persistence with migrations, and integration tests against a real database — so the build is green from the first commit rather than after days of gluing fragments.

The [resource] variable names the API resource and shapes the DTOs, entity, and CRUD endpoints. [java_version] sets the language level (records, pattern matching, and so on), [database] drives the JPA dialect and Flyway migrations, and [base_path] is where the controller exposes its routes. The result uses Java records for request/response DTOs with Bean Validation, an exception handler returning RFC 7807 problem details, and Testcontainers tests that hit the actual [database] rather than an in-memory substitute, so dialect-specific behavior is exercised.

When to use it

  • Standing up a new Spring Boot 3 REST resource with validation and migrations done correctly.
  • Wanting RFC 7807 problem-details error responses instead of ad-hoc error JSON.
  • Generating an OpenAPI spec and Swagger UI alongside the endpoints via springdoc.
  • Adding Testcontainers integration tests that exercise the real database, not H2.
  • Establishing a clean, conventional JVM backend for a client on the Spring stack.
  • Producing CRUD with pagination and sorting under a fixed base path without hand-wiring it.

Example output

You get the package tree first, then each file in its own fenced block with the path as a header. That includes Java record DTOs with Bean Validation, the global exception handler, the JPA entity and repository, Flyway migrations creating the schema, a CRUD controller under [base_path] with pagination and sorting, springdoc OpenAPI config, and Testcontainers tests covering the happy path plus validation failures. It's a coherent, compilable slice you extend, not scattered fragments, and the structure mirrors a conventional Spring Boot layout your team will recognise.

Pro tips

  • Pin your Flyway baseline early — retrofitting migrations onto an existing schema is the painful part, so start clean if you can.
  • Set [database] to your real target so the dialect, types, and Testcontainers image all match production.
  • Name [resource] with its real fields and relationships so the DTOs, entity, and validation reflect your actual model.
  • Choose [java_version] to match your build; records and newer syntax only work if the compiler level supports them.
  • Use [base_path] consistently with your API versioning scheme so routes line up with the rest of the service.
  • Keep the RFC 7807 handler as the single error path so every endpoint returns consistent problem-details responses.

Frequently Asked Questions

Does it return a full project or just code snippets?
The prompt instructs the model to return complete, compilable Spring Boot 3 code with the project structure, each file in its own block with its path as a header. You still verify it builds locally, but the intent is a coherent project rather than disconnected fragments.
What error format does the generated API use?
It uses a global exception handler returning RFC 7807 problem details, the standard structured format for HTTP API errors. Keeping this as the single error path means validation failures and other exceptions all return consistent, machine-readable responses across every endpoint.
How are the integration tests set up?
Tests use Testcontainers to spin up the real database defined by `[database]` and exercise the happy path plus validation failures. Testing against the actual database rather than an in-memory one catches dialect-specific and migration issues that H2 would hide.
Can I target a specific Java version and database?
Yes. The `[java_version]` variable sets the language level so records and newer syntax compile, and `[database]` drives the JPA dialect, Flyway migrations, and the Testcontainers image. Match both to your build and production environment to avoid mismatches.
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

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