Search This Blog

Sunday, October 13, 2013

Spring REST - access HTTP header data on the server side

This is an example of a simple REST call on the server side;

The call looks like the following:

[GET] http://localhost:8080/rest/user/getUser/userNameABC
Accept: application/json
Authorization: 123456


@RequestMapping(value="/getUser/{login}", method = RequestMethod.GET, produces="application/json", headers="Accept=application/json")
@ResponseBody
public User getUser(
   @RequestHeader(value = "Authorization", required = true) String authorization,
   @PathVariable String login) {
   
     if (login.isEmpty())
        return null;

     [....]
}

The @RequestHeader accesses for us data in the header. We can also get the Accept parameter by adding:

@RequestHeader(value = "Accept") String acceptString


No comments:

Post a Comment

If you like this post, please leave a comment :)