REST API Articles
Articles covering REST API design, error handling, input validation, authentication, pagination, and other key backend implementation topics.
-
How to Implement Pagination with Spring Boot + MyBatis - Choosing Between PageHelper, RowBounds, and Hand-Written LIMIT/OFFSET
Compares three approaches to paginating list APIs in Spring Boot + MyBatis (hand-written LIMIT/OFFSET, RowBounds, and PageHelper) in terms of generated SQL, count retrieval, sorting, and extra dependencies. Explains why RowBounds results in in-memory pagination, the thread-local pitfalls of PageHelper and its helperDialect setting, and how to convert to Spring Data's Pageable, all with ready-to-run code.
-
How to Validate List<DTO>, @RequestParam, and @PathVariable in Spring Boot - Why @Valid Doesn't Work and How to Handle the 3 Exceptions
A reverse-lookup guide to why element validation of a List-typed DTO annotated with @Valid, or @Min on @RequestParam/@PathVariable, doesn't work in Spring Boot 3.x, and how to fix it. Covers the differences between the 3 exceptions, unified error responses with @RestControllerAdvice, and indexed messages in the users[1].name format.
-
How to Receive Request Parameters in Spring Boot - Choosing Between @RequestParam, @PathVariable, @RequestBody, and @ModelAttribute
A guide to the four annotations for receiving client input in Spring Boot Controllers—@RequestParam, @PathVariable, @RequestBody, and @ModelAttribute—with criteria for choosing between them based on the input source: query strings, path variables, JSON bodies, and forms. Covers required/defaultValue, multiple values with List, and the 400 behavior on type conversion failures with implementation examples.
-
How to Export and Read Excel Files in Spring Boot - Implementing Reports and Data Import with Apache POI
An implementation guide for exporting and reading Excel (xlsx) files with Spring Boot and Apache POI. Covers the basics of Workbook/Sheet/Cell, downloading via REST API, memory optimization for large datasets with SXSSFWorkbook, and parsing uploaded xlsx files, all with code examples.
-
Customizing JSON Serialization with Jackson in Spring Boot - A Guide to Date Formatting, Null Exclusion, and snake_case
Solve common Jackson issues in Spring Boot such as 'LocalDateTime is returned as an array' and 'the frontend requires snake_case'. This REST API implementation guide covers date formatting, null exclusion, snake_case conversion, @JsonView, Mixins, and custom Serializers with code examples.
-
Implementing Spring Boot's GlobalExceptionHandler for Production Use
This article explains how to implement Spring Boot's GlobalExceptionHandler (@RestControllerAdvice) with production-ready quality. It introduces implementation patterns needed in the operational phase, such as stack trace logging, traceID assignment via MDC, and custom property extensions to ProblemDetail, with concrete code examples.
-
How to Implement Idempotency (Idempotency-Key) in a Spring Boot REST API - Preventing Double Charges and Double-Clicks
Learn how to implement the Idempotency-Key header pattern in Spring Boot to prevent double charges and duplicate execution caused by double-clicks on payment APIs. Covers implementation code using OncePerRequestFilter and Redis, lock control for concurrent requests, TTL design, and production operation caveats from a practical perspective.
-
Understanding Spring Security CSRF Protection Correctly - Configuration Differences Between REST APIs and Web Apps
Solve the cause of POST returning 403 in Spring Security by understanding the CSRF mechanism. From why `csrf().disable()` is correct for REST APIs, the required settings for Thymeleaf forms, to AJAX support via `CookieCsrfTokenRepository.withHttpOnlyFalse()`, organized with Spring Security 6 Lambda DSL implementation examples.
-
How to Standardize Error Responses with Problem Details (RFC 9457) in Spring Boot 3.x
Learn how to unify error responses using Problem Details (RFC 9457), now supported out of the box in Spring Boot 3.x. This guide covers the spring.mvc.problemdetails.enabled setting, how to use the ProblemDetail class and ErrorResponse, integrating @ControllerAdvice with ResponseEntityExceptionHandler, migration steps from Spring Boot 2.x, and applying Problem Details to Spring Security and validation errors, all with code examples.
-
How to Use GraphQL with Spring Boot - Spring for GraphQL Basics and When to Use It vs REST API
Using Spring for GraphQL in Spring Boot 3.x, this guide covers schema definition, Query and Mutation Resolver implementation, handling N+1 problems with DataLoader, and integration with Spring Security. Includes a comparison with REST API to clarify when to choose GraphQL.
-
Spring Boot REST API Versioning Strategies - Choosing Between URL Path, Header, and Content-Type
Compare three approaches to versioning REST APIs in Spring Boot (URI path, custom header, and Accept header) with working implementation code. Covers decision criteria for choosing the approach that fits your team's API characteristics, plus a Swagger UI integration example.
-
How to Implement Internationalization (i18n) in Spring Boot - Using MessageSource and LocaleResolver
A practical guide to implementing internationalization (i18n) in Spring Boot REST APIs. Covers language switching via the Accept-Language header, locale fallback with messages.properties, configuring MessageSource and AcceptHeaderLocaleResolver, localizing @Valid validation error messages, and returning multilingual error responses with @RestControllerAdvice, all in one end-to-end walkthrough.
-
Implementing REST API CRUD in Spring Boot - The Basic Controller, Service, and Repository Structure
A step-by-step guide to implementing REST API CRUD (Create, Read, Update, Delete) in Spring Boot using the three-layer Controller, Service, and Repository architecture. Get the four GET/POST/PUT/DELETE endpoints running with copy-paste code, and verify them end-to-end with curl.
-
How to Configure CORS in Spring Boot - Choosing Between @CrossOrigin and WebMvcConfigurer
A practical guide to resolving CORS errors when calling a Spring Boot REST API from frontends like React or Vue. Covers when to use each of the three approaches (@CrossOrigin, WebMvcConfigurer, and SecurityFilterChain), plus the pitfalls to watch for when introducing Spring Security.
-
How to Auto-Generate REST API Documentation Using OpenAPI (Swagger UI) with Spring Boot
A practical guide covering the introduction of springdoc-openapi, enhancing documentation with annotations, configuring Bearer token for JWT-authenticated endpoints, and YAML output.
-
Difference Between Interceptor and Filter in Spring Boot - With Implementation Samples for Request Pre/Post Processing
For those wondering which to use between Spring Boot's Filter and HandlerInterceptor, this article first presents the criteria for choosing between them. It organizes the differences in execution timing, Spring DI management, and available information, then explains use cases such as authentication checks, request logging, CORS, and exception handling with implementation samples.
-
How to Call REST APIs in Spring Boot - When to Use RestTemplate vs WebClient
A practical guide to the two main approaches for calling external REST APIs in Spring Boot: RestTemplate and WebClient. Covers basic usage, criteria for choosing between them, timeout configuration, and error handling.
-
Spring Boot JWT Authentication with Spring Security (Tutorial)
Build JWT authentication for a Spring Boot REST API from scratch. Covers token generation, validation, JwtAuthenticationFilter, and SecurityFilterChain configuration with complete code examples.
-
How to Implement Pagination in Spring Boot REST API - Using Pageable and Page
Step-by-step guide to implementing REST API pagination using Spring Data JPA's Pageable and Page. Covers page specification via query parameters, sort conditions, custom response formats, and error handling with practical code examples.
-
How to Return Unified Error Responses in Spring Boot REST APIs - Using @ControllerAdvice and @ExceptionHandler (with @RestControllerAdvice / ResponseEntityExceptionHandler)
Struggling with inconsistent error responses across Controllers? This guide explains how to use @ControllerAdvice, @RestControllerAdvice, and @ExceptionHandler in Spring Boot REST APIs to return validation errors, business errors, and system errors in a unified JSON format. It also covers the design pattern of extending ResponseEntityExceptionHandler to standardize Spring MVC's built-in exceptions, with code examples.