REST API Articles
Articles covering REST API design, error handling, input validation, authentication, pagination, and other key backend implementation topics.
-
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 Configuration in Spring Boot - Date, Null Exclusion, and snake_case Guide
Solve common Jackson issues in Spring Boot such as 'LocalDateTime returned as array' and 'frontend requires snake_case'. This REST API implementation guide explains date formatting, null exclusion, snake_case conversion, and @JsonView/Mixin/custom Serializer 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 Spring Boot REST APIs - Preventing Double Charges and Double Clicks
Explains how to implement the Idempotency-Key header approach in Spring Boot to prevent double charges and double execution caused by double-clicks in payment APIs. Covers implementation code using OncePerRequestFilter and Redis, lock control for concurrent requests, TTL design, and production operation considerations 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 with Problem Details (RFC 9457), natively supported in Spring Boot 3.x. This guide covers the spring.mvc.problemdetails.enabled setting, how to use the ProblemDetail class and ErrorResponse, integration with @ControllerAdvice and ResponseEntityExceptionHandler, migration steps from Spring Boot 2.x, and application 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 REST API versioning approaches in Spring Boot (URI path, custom header, Accept header) with implementation code. Includes decision criteria for choosing the right strategy for your team's API characteristics and Swagger UI integration examples.
-
How to Implement Internationalization (i18n) in Spring Boot - Using MessageSource and LocaleResolver
An implementation guide for achieving internationalization (i18n) in Spring Boot REST APIs. Covers everything from language switching via the Accept-Language header, locale fallback in messages.properties, configuring MessageSource and AcceptHeaderLocaleResolver, localizing @Valid validation error messages, to multilingual error responses with @RestControllerAdvice.
-
Implementing REST API CRUD with Spring Boot - Basic Structure of Controller, Service, and Repository
A step-by-step guide to implementing REST API CRUD (Create, Read, Update, Delete) with Spring Boot using a three-layer structure of Controller, Service, and Repository. Get the four GET/POST/PUT/DELETE endpoints running via copy-paste, with end-to-end coverage including verification using curl.
-
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 API - Using @ControllerAdvice and @ExceptionHandler (@RestControllerAdvice / ResponseEntityExceptionHandler Support)
Are you struggling with inconsistent error responses across Controllers? This article explains how to use @ControllerAdvice, @RestControllerAdvice, and @ExceptionHandler in Spring Boot REST API to return validation errors, business errors, and system errors in a unified JSON format. Learn design patterns and code examples for extending ResponseEntityExceptionHandler to standardize Spring MVC default exceptions as well.