- Home
- Skills
- APIs & Backend
- Spring REST Controllers
Spring REST Controllers
Generate production-ready Spring REST controllers with validation, HATEOAS, and global exception handling.
Free
Works with the AI tools you already use
Spring REST Controllers
Example session with this skill installed
Create a Spring REST controller for a Product resource with validation, DTOs, and a global exception handler for ResourceNotFoundException.
- Read your context and instructions
- Compiled the spring rest controllers
I have generated a production-ready REST implementation for the Product resource, including validation, DTO mapping, and global error handling.
Spring REST Product Implementation
// ProductDTO.java
@Data
public class ProductDto {
@NotBlank(message = "Product name is required")
private String name;
@Positive(message = "Price must be greater than zero")
private BigDecimal price;
}
// ProductController.java
@RestController
@RequestMapping("/api/products")
@RequiredArgsConstructor
public class ProductController {
private final ProductService productService;
@PostMapping
public ResponseEntity<ProductDto> create(@Valid @RequestBody ProductDto dto) {
ProductDto created = productService.save(dto);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(created.getId())
.toUri();
return ResponseEntity.created(location).body(created);
}
@GetMapping("/{id}")
public ResponseEntity<ProductDto> get(@PathVariable Long id) {
return productService.findById(id)
.map(ResponseEntity::ok)
.orElseThrow(() -> new ResourceNotFoundException("Product " + id + " not found"));
}
}
// GlobalExceptionHandler.java
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<ErrorResponse> handleNotFound(ResourceNotFoundException ex) {
ErrorResponse error = ErrorResponse.builder()
.code("NOT_FOUND")
.message(ex.getMessage())
.timestamp(Instant.now())
.build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(error);
}
}
Next steps
- Add
spring-boot-starter-validationto yourpom.xmlif not present. - Implement the
ProductServiceinterface and its persistence logic. - Define the
ErrorResponserecord to match your corporate API standards.
Connects securely to your tools. The creator never sees your data.
About this skill
The problem
Building Spring REST APIs often leads to inconsistent error responses, missing input validation, and improper use of HTTP status codes. Developers frequently leak internal entities directly to the client or fail to provide proper HATEOAS links and location headers.
What it does
- Generates standard REST controllers using ResponseEntity and DTO patterns.
- Implements global exception handling with @RestControllerAdvice for consistent error schemas.
- Configures JSR-303/380 validation for request bodies including validation groups.
- Sets up HATEOAS link assembly for discoverable APIs.
- Provides templates for API versioning via URLs, headers, or media types.
Frameworks & tools
Spring Boot, Spring Web MVC, Spring HATEOAS, Jakarta Validation, and Jackson.
Why this beats prompting it yourself
Standard LLM prompts often provide basic controllers that ignore production requirements like MDC logging, streaming responses, and proper content negotiation. This skill enforces strict architectural patterns, ensuring every endpoint includes correct headers, status codes, and error wrappers without manual correction.
Use cases
- Scaffolding a new microservice with standardized CRUD endpoints.
- Implementing a global error handling strategy across an existing Spring application.
- Adding HATEOAS support to existing JSON resources.
- Configuring multi-version API support for legacy client compatibility.
Known limitations
Does not support Spring WebFlux, GraphQL, or gRPC. Deep HATEOAS customizations require the specialized spring-hateoas skill.
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
3 installs
Downloaded by developers to date
Free forever
No account required to browse
Trust & safety
Security scanned
Verified clean 12 days ago
- Free to download with an account