Home > Blockchain >  Spring REST API - HEAD Request
Spring REST API - HEAD Request

Time:06-08

I have built a REST API with Spring, and I was looking into the HEAD Request; how do I know if it is working?

@RequestMapping(value="/employees", method= RequestMethod.GET) //used to get all employees
        
@RequestMapping(value="/employees", method= {RequestMethod.GET, RequestMethod.HEAD}) //same but I added the head request method

In Postman, both of these return the same values under Headers in a HEAD Request - so do I need to add the RequestMethod.HEAD or not? How can I check it is working?

Thanks!

CodePudding user response:

@RequestMapping methods mapped to GET are also implicitly mapped to HEAD, i.e. there is no need to have HEAD explicitly declared. An HTTP HEAD request is processed as if it were an HTTP GET except instead of writing the body only the number of bytes are counted and the Content-Length header set.

  • Related