Creates Spring REST APIs following best practices.
Creates Spring REST APIs with proper package structure, converters for binding path variables to value objects, Jackson annotations for request body mapping, and RFC 7807 compliant exception handling.
/plugin marketplace add sivaprasadreddy/sivalabs-marketplace/plugin install spring-boot-dev@sivalabs-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
The following are key principles to follow while creating Spring REST APIs:
@PathVariable and @RequestParam to Value Objects@RequestBody binding to Request Objects with Value Object properties@JsonUnwrapped to map flattened JSON to nested objects@Valid annotationimport org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
public class StringToEventCodeConverter implements Converter<String, EventCode> {
@Override
public EventCode convert(String source) {
return new EventCode(source);
}
}
This allows Spring MVC to automatically convert path variables like /{eventCode} from String to EventCode:
@GetMapping("/{eventCode}")
ResponseEntity<EventVM> findEventByCode(@PathVariable EventCode eventCode) {
// eventCode is already an EventCode object, not a String
}
Use @JsonValue and @JsonCreator annotations to bind primitives to Request Bodies with Value Objects.
EventCode Value Object:
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.validation.constraints.NotBlank;
public record EventCode(
@JsonValue
@NotBlank(message = "Event code cannot be null or empty")
String code
) {
@JsonCreator
public EventCode {
if (code == null || code.trim().isEmpty()) {
throw new IllegalArgumentException("Event code cannot be null");
}
}
public static EventCode of(String code) {
return new EventCode(code);
}
}
CreateEventRequest Request Payload:
record CreateEventRequest(
@Valid EventCode code
// ... other properties
) {
}
Now Spring MVC will automatically bind the code property from the JSON payload to EventCode object.
{
"code": "ABSHDJFSD",
"property-1": "value-1",
"property-n": "value-n"
}
Use @JsonUnwrapped and @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) annotations to map flattened JSON to nested objects.
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
public record EventDetails(
@NotBlank(message = "Title is required")
@Size(min = 3, max = 200, message = "Title must be between 3 and 200 characters")
String title,
@NotBlank(message = "Description is required")
@Size(max = 10000, message = "Description cannot exceed 10000 characters")
String description,
@Size(max = 500, message = "Image URL cannot exceed 500 characters")
@Pattern(regexp = "^https?://.*", message = "Image URL must be a valid HTTP/HTTPS URL")
String imageUrl) {
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public EventDetails(
@JsonProperty("title") String title,
@JsonProperty("description") String description,
@JsonProperty("imageUrl") String imageUrl
) {
this.title = AssertUtil.requireNotNull(title, "title cannot be null");
this.description = AssertUtil.requireNotNull(description, "description cannot be null");
this.imageUrl = imageUrl;
}
public static EventDetails of(String title, String description, String imageUrl) {
return new EventDetails(title, description, imageUrl);
}
}
CreateEventRequest Request Payload:
record CreateEventRequest(
@Valid EventCode code,
@JsonUnwrapped @Valid EventDetails details
// ... other properties
) {
}
Now Spring MVC will automatically bind the title, description and imageUrl property values
from the JSON payload to EventDetails object.
{
"code": "ABSHDJFSD",
"title": "Spring Boot Workshop",
"description": "Learn Spring Boot best practices",
"imageUrl": "https://example.com/image.jpg",
"property-1": "value-1",
"property-n": "value-n"
}
Create a centralized exception handler that returns ProblemDetail responses.
Create a class GlobalExceptionHandler by following the following key principles:
@RestControllerAdviceResponseEntityExceptionHandlerProblemDetail for RFC 7807 complianceimport dev.sivalabs.meetup4j.shared.DomainException;
import dev.sivalabs.meetup4j.shared.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.core.env.Environment;
import org.springframework.http.*;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
@RestControllerAdvice
class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
private final Environment environment;
GlobalExceptionHandler(Environment environment) {
this.environment = environment;
}
@Override
public ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
log.error("Validation error", ex);
var errors = ex.getAllErrors().stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.toList();
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(BAD_REQUEST, ex.getMessage());
problemDetail.setTitle("Validation Error");
problemDetail.setProperty("errors", errors);
return ResponseEntity.status(UNPROCESSABLE_CONTENT).body(problemDetail);
}
@ExceptionHandler(DomainException.class)
public ProblemDetail handle(DomainException e) {
log.info("Bad request", e);
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(BAD_REQUEST, e.getMessage());
problemDetail.setTitle("Bad Request");
problemDetail.setProperty("errors", List.of(e.getMessage()));
return problemDetail;
}
@ExceptionHandler(ResourceNotFoundException.class)
public ProblemDetail handle(ResourceNotFoundException e) {
log.error("Resource not found", e);
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(NOT_FOUND, e.getMessage());
problemDetail.setTitle("Resource Not Found");
problemDetail.setProperty("errors", List.of(e.getMessage()));
return problemDetail;
}
@ExceptionHandler(Exception.class)
ProblemDetail handleUnexpected(Exception e) {
logger.error("Unexpected exception occurred", e);
// Don't expose internal details in production
String message = "An unexpected error occurred";
if (isDevelopmentMode()) {
message = e.getMessage();
}
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(INTERNAL_SERVER_ERROR, message);
problemDetail.setProperty("timestamp", Instant.now());
return problemDetail;
}
private boolean isDevelopmentMode() {
List<String> profiles = Arrays.asList(environment.getActiveProfiles());
return profiles.contains("dev") || profiles.contains("local");
}
}
Validation Error (400):
{
"type": "about:blank",
"title": "Validation Error",
"status": 400,
"detail": "Validation failed for argument...",
"errors": [
"Title is required",
"Email must be valid"
]
}
Domain Exception (400):
{
"type": "about:blank",
"title": "Bad Request",
"status": 400,
"detail": "Cannot cancel events that have already started",
"errors": [
"Cannot cancel events that have already started"
]
}
Resource Not Found (404):
{
"type": "about:blank",
"title": "Resource Not Found",
"status": 404,
"detail": "Event not found with code: ABC123",
"errors": [
"Event not found with code: ABC123"
]
}
Internal Server Error (500):
{
"type": "about:blank",
"title": "Internal Server Error",
"status": 500,
"detail": "An unexpected error occurred",
"timestamp": "2024-01-15T10:30:00Z"
}
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.