- Home
- Skills
- APIs & Backend
- Spring REST Controllers
Spring REST Controllers
Generate production-ready Spring REST controllers with validation, HATEOAS, and global exception handling.
Free
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 use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
5 uses
Times used to date
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 2 months ago
- Free with an Agensi account
Permissions
No special permissions declared or detected
What's inside
Frequently Asked Questions
New in APIs & Backend
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.