REST API Articles
Articles covering REST API design, error handling, input validation, authentication, pagination, and other key backend implementation topics.
-
Customizing JSON Serialization with Jackson Configuration in Spring Boot
A guide to Spring Boot's Jackson configuration covering date formatting, null exclusion, snake_case conversion, and custom Serializers with code examples. An implementation guide for controlling REST API JSON output as intended.
-
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 implement RFC-compliant error responses using the ProblemDetail class and ErrorResponse interface, leveraging the built-in Problem Details (RFC 9457) support introduced in Spring Boot 3.x. Includes migration steps from custom error response formats.
-
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
A comprehensive guide to implementing internationalization in Spring Boot REST APIs using the Accept-Language header. Covers everything from configuring messages.properties and selecting a LocaleResolver, to localizing @Valid validation error messages and returning 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.
-
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.