How do you implement OAuth 2.0 authentication for REST APIs in Spring Boot?
Protect REST endpoints in Spring Boot by validating bearer JWTs with the OAuth 2.0 resource server support in Spring Security, including scopes and roles.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Protect REST endpoints in Spring Boot by validating bearer JWTs with the OAuth 2.0 resource server support in Spring Security, including scopes and roles.
Use @RestController and the HTTP method mappings to build a REST API in Spring MVC, with validation, content negotiation and central error handling.
HttpHeaders is Spring's typed class for reading and building HTTP headers. See how to use it with ResponseEntity, @RequestHeader and RestClient.
@ModelAttribute binds form and query parameters to an object and shares data with the view. Learn forms, validation and mass assignment safety.
Authenticate REST APIs in Spring Boot 3 with SecurityFilterChain, HTTP Basic or OAuth2 JWT resource server, with password hashing and method security.
Spring MVC maps query and form parameters onto objects with @ModelAttribute. See records, validation, nested binding, @RequestParam and safe binding.
ResponseErrorHandler defines how RestTemplate detects and handles HTTP errors. Learn the default behaviour, custom handlers and the RestClient equivalent.
@InitBinder lets a controller customise how request data is bound to objects. See date formats, validators, field whitelists and @ControllerAdvice.
Learn how RestTemplate reports 4xx, 5xx and I/O errors, how to catch them, write a custom ResponseErrorHandler and map failures to ProblemDetail responses.
Use WebClient for non-blocking HTTP calls in Spring Boot, or RestClient with virtual threads and CompletableFuture for blocking code. Includes timeouts, retries and parallel calls.
WebClient is Spring's non-blocking, reactive HTTP client. See how to build it, call APIs, handle errors, set timeouts and when to choose it over RestClient.
Set up a RestTemplate bean with RestTemplateBuilder, timeouts, interceptors and error handling, and see how RestClient replaces it in new code.
RestTemplate is Spring's blocking HTTP client for consuming REST APIs. See GET, POST, PUT and DELETE examples, error handling and the RestClient alternative.
Call external REST APIs from Spring Boot with RestClient and @HttpExchange: GET, POST, timeouts, error handling, tests and when to use WebClient.
Spring has no GraphQLFilter class. Use WebGraphQlInterceptor, servlet filters and instrumentation to intercept and secure GraphQL requests.
Protect the GraphQL endpoint with JWT, authorize each query, mutation and field with method security, and limit query depth and complexity.
DataFetcher resolves one field in a GraphQL schema. See how Spring for GraphQL wraps controllers, batches loads and registers fetchers manually.
Add the Spring for GraphQL starter, define a schema and map fields with @QueryMapping, @SchemaMapping and @BatchMapping. Includes argument binding and a controller test.
Define custom exceptions and handle them globally with @ControllerAdvice, ProblemDetail JSON responses and ResponseEntityExceptionHandler in Spring 6.
@ResponseStatus sets the HTTP status for a Spring controller method or exception class. Learn how it works, its limits and when to use ResponseStatusException.