Posts

Showing posts with the label @RequestHeader

Spring @RequestHeader Annotation Example

Image
In this section we will learn about  @RequestHeader  Annotation.   Spring MVC provides an annotation  @RequestHeader  for facilitating use to get the header details easily in our controller class. This annotation would bind the header details with the method arguments, and it can be used inside the methods. Given below are the available fields that you can pass optionally defaultValue : The default value to use as a fallback. name : The name of the request header to bind to. required : Whether the header is required. value : Alias for name If the method parameter is  Map<String, String> , or  HttpHeaders  then the map is populated with all header names and values. @RestController public class UserController { @GetMapping ( "/users" ) public User getUser ( @RequestHeader String token ) { //TODO } } The following example creates a Spring Boot web application which uses @RequestHeader . The application receives an URL fr...