REST API Articles
Articles covering REST API design, error handling, input validation, authentication, pagination, and other key backend implementation topics.
-
How to Implement Idempotency (Idempotency-Key) in Spring Boot REST APIs
A practical guide to implementing Idempotency-Key header-based idempotency in Spring Boot, covering implementation code using Filter and Redis, concurrent request handling, and TTL design.
-
Understanding Spring Security CSRF Protection Correctly - Configuration Differences Between REST APIs and Web Applications
Explains why POST requests return 403 in Spring Security from the perspective of how CSRF works. Covers why csrf().disable() is the correct approach for REST APIs, why it should be enabled for Thymeleaf form-based apps, along with implementation examples using Spring Security 6's Lambda DSL.
-
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 CRUD REST API with Spring Boot - Basic Structure of Controller, Service, and Repository
A step-by-step guide to implementing CRUD (Create, Read, Update, Delete) REST API with Spring Boot. Build the three-layer architecture of Controller, Service, and Repository from scratch, and walk through setting up all four endpoints: GET, POST, PUT, and DELETE.
-
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.