'How to make a header that do the accounting purpose in springboot

API should also read a header. X-User - This will be a numeric number used for accounting purpose. This will be used as the user id.



Solution 1:[1]

There are several different ways of reading a header on a REST API controller using java and spring-boot project with Spring Web dependency. As you're looking for a specific header you could use this Spring annotation:

@RequestHeader

@GetMapping("/get-end-point")
public ResponseEntity<String> foo(@RequestHeader("X-User") Integer accountingNumber) {
// code that uses the number for accounting purpose
return new ResponseEntity<String>(mockResourceString, HttpStatus.OK);

}

Check out this tutorial here if you want to know more.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Giuliano