spring-boot-rest-api-standards

Implements REST API design standards for Spring Boot endpoints, DTOs, and error handling.

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill spring-boot-rest-api-standards-412181-heredialara
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spring-boot-rest-api-standards
Source: https://github.com/412181-HerediaLara/ScaffoldingBE-FE/tree/main/BE/.agents/skills/spring-boot-rest-api-standards
Command: npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill spring-boot-rest-api-standards-412181-heredialara

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Building consistent, well-structured REST APIs in Spring Boot requires many decisions about URL design, HTTP methods, status codes, validation, error handling, pagination, and security headers. This Skill provides a single authoritative reference so teams avoid inconsistent endpoints, missing validation, and non-standard error responses. ## Core Features & Use Cases - REST Endpoint Standards: Enforces resource-based URLs, correct HTTP methods, and proper status codes (201 with Location header, 204 for deletes, 409 for conflicts). - DTO and Validation Patterns: Guides separation of API contracts from domain entities using records or Lombok, with Jakarta validation annotations and global exception handling via @RestControllerAdvice. - Pagination, Filtering, and Security: Covers Pageable-based pagination, Specification-based filtering, CORS configuration, and security headers like CSP, HSTS, and X-Frame-Options. - Use Case: When building a new /api/users CRUD controller, use this Skill to generate the controller, request/response DTOs with validation, a global exception handler, and paginated list endpoints that follow REST conventions. ## Quick Start Use the spring-boot-rest-api-standards skill to create a validated, paginated CRUD REST controller for the Product entity with proper status codes and a global exception handler.

Frequently Asked Questions about spring-boot-rest-api-standards

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a REST API endpoint in Spring Boot?

Create a @RestController class with @RequestMapping for the base path, then use @GetMapping, @PostMapping, @PutMapping, and @DeleteMapping for operations. Return ResponseEntity with appropriate status codes like 201 for creation and 204 for deletion.

How to validate request body in Spring Boot REST API?

Add @Valid to the @RequestBody parameter and annotate DTO fields with Jakarta constraints like @NotBlank, @Email, and @Size. Handle MethodArgumentNotValidException in a @RestControllerAdvice to return standardized 400 error responses.

Should I expose JPA entities directly in REST controllers?

No, always use separate request and response DTOs to decouple API contracts from domain entities. This prevents leaking internal fields, avoids lazy-loading serialization issues, and lets the API evolve independently of the database schema.

How do I add pagination to a Spring Boot REST endpoint?

Accept page and size request parameters, build a Pageable with PageRequest.of(page, size, sort), and return a Page<T> from the repository. Include metadata like totalElements and totalPages, and cap the maximum page size to prevent abuse.

What HTTP status codes should a REST API return?

Return 200 for successful reads and updates, 201 with a Location header for creation, 204 for deletes, 400 for validation failures, 404 for missing resources, and 409 for conflicts such as duplicate emails. Handle errors globally with @RestControllerAdvice.

How do I configure CORS and security headers in Spring Boot?

Define a SecurityFilterChain bean that configures a CorsConfigurationSource with allowed origins, methods, and headers. Add security headers including Content-Security-Policy, Strict-Transport-Security, X-Content-Type-Options, and X-Frame-Options through the headers DSL.