Q:

How can I access access header values of a REST GET message with Spring/Kotlin

For restful communication I am building a Server-Backend with Kotlin using Spring.
I have the following code for a GET request. For now I am pretty new to Kotlin and also to the Spring library. Can somebody explain me, how I can access the values in the header of the GET message? 
I guess @RequestHeader is somehow used for this? Will it be the same for other message types as POST, UPDATE etc?
@CrossOrigin
@RestController
class UserRestController(val userManager: UserManager) {

    @GetMapping("specific_user_lean")
    fun getSpecificUserLean(@RequestParam(value ="id") id: String) = run {
        userManager.loadUserByID(id) // returns null or a User object
    }
}

A:

You can use for it @RequestHeader as stated in spring documentation:
https://docs.spring.io/spring/docs/5.2.x/spring-framework-reference/web.html#mvc-ann-requestheader
There is also example for Kotlin: 
@GetMapping("/demo")
fun handle(
    @RequestHeader("Accept-Encoding") encoding: String, 
    @RequestHeader("Keep-Alive") keepAlive: Long) { 
    //...
}

This example accepts "Accept-Encoding" and "Keep-Alive" headers.
If you want to accept all headers, than you should collect them in Map.
@GetMapping("/demo")
fun handle(
    @RequestHeader allHeaders: Map<String, String>) { 
    //...
}

Yes, @RequestHeader annotation works for POST, PUT and other methods.

