</>

Technology

Rest Assured

Difficulty

Intermediate

Interview Question

What is the HEAD HTTP method and when do you use it?

Answer

HEAD Method

The HEAD method asks for a response identical to a GET request, but without the response body.

Use Cases

  • Check if a resource exists without downloading it
  • Get metadata (Content-Type, Content-Length, Last-Modified) without the actual content
  • Performance optimization — verify headers before making full GET
  • Link validation — check URLs are alive without fetching full pages

Example

CODE
HEAD /api/files/large-document.pdf HTTP/1.1
Host: api.example.com

Response:
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 2097152
Last-Modified: Thu, 19 Jun 2026 10:00:00 GMT

No body is returned — just the headers.

In Rest Assured

Java
Response response = given()
    .when()
    .head("https://api.example.com/users/1");

assertEquals(response.getStatusCode(), 200);
// response.getBody() will be empty

HEAD vs GET

FeatureHEADGET
Returns headersYesYes
Returns bodyNoYes
Use for metadataYesPossible but inefficient

Follow AutomateQA

Related Topics