Spring REST Controllers

    by claude-dev-suite

    1

    Generate production-ready Spring REST controllers with validation, HATEOAS, and global exception handling.

    Free

    5 usesSecurity scanned

    Works with the AI Agents 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

    1. Add spring-boot-starter-validation to your pom.xml if not present.
    2. Implement the ProductService interface and its persistence logic.
    3. Define the ErrorResponse record 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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

    Listed2 months ago

    What's inside

    Frequently Asked Questions

    This skill provides ready-to-use templates and logic to generate robust Spring REST controllers that include mandatory production features like HATEOAS links, JSR-303 validation, and standardized global exception handling.

    It is compatible with all major AI agents that support code generation tasks, specifically those optimized for Java and Spring Boot ecosystems.

    No, this skill is specifically designed for the Spring Web MVC stack; it does not currently support reactive programming with Spring WebFlux or alternative protocols like GraphQL.

    You receive the complete architectural logic for generating controllers, DTO patterns, @RestControllerAdvice templates, and configuration for HATEOAS and Jakarta Validation.

    The skill generates controllers that follow industry best practices, including the use of ResponseEntity, proper HTTP status codes, and Location headers for POST requests.

    Simply import the skill into your preferred AI agent and provide your entity details; it will output the controller and supporting architectural classes ready for your project.

    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.

    Free