Hi,
I am looking for the differences and similarities of Head and Get method in Web , And I need a few examples about each of these.
Thank you very much.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Joe WilsonPosted Nov 27, 2016, 11:41 AM
Bikesh SrivastavaPosted Nov 27, 2016, 6:58 AM
A RESTful URI should represent a "resource" at the server. Resources are often stored as a record in a database or a file on the filesystem. Unless the resource is large or is slow to retrieve at the server, you might not see a measurable gain by using
HEADinstead ofGET. It could be that retrieving the meta data is not any faster than retrieving the entire resource.You could implement both options and benchmark them to see which is faster, but rather than micro-optimize, I would focus on designing the ideal REST interface. A clean REST API is usually more valuable in the long run than a kludgey API that may or may not be faster. I'm not discouraging the use of
HEAD, just suggesting that you only use it if it's the "right" design.If the information you need really is meta data about a resource that can be represented nicely in the HTTP headers, or to check if the resource exists or not,
HEADmight work nicely.For example, suppose you want to check if resource 123 exists. A
200means "yes" and a404means "no":However, if the "yes" or "no" you want from your REST service is a part of the resource itself, rather than meta data, you should use
GET.Joe WilsonPosted Nov 26, 2016, 12:40 PM
Khaja MoizuddinPosted Nov 25, 2016, 10:02 PM