QA
Beginner LevelREST APIs & Web Services

What are the HTTP HEAD and OPTIONS methods used for in REST APIs?

❓ Interview Prompt: Explain `HEAD` (fetching headers without body for link checking/file size validation) and `OPTIONS` (querying API capabilities and CORS rules).

1. 'HEAD' Method:

Identical to 'GET', except the server MUST NOT return a message body in the response. Returning only response headers allows clients to check if a file exists, inspect 'Content-Length', or check 'ETag' without downloading massive payloads!

2. 'OPTIONS' Method:

Queries the target server to describe communication options and supported HTTP methods available for a target URI (used extensively in CORS preflight queries).

Code Implementation Example

http
// Requesting HEAD to check file size without downloading body:
HEAD /files/large_archive.zip HTTP/1.1
Host: api.example.com

// Server Response (No Body!):
HTTP/1.1 200 OK
Content-Type: application/zip
Content-Length: 5368709120
ETag: "archive_v1_hash"
💡HTTP HEAD request checking Content-Length headers without downloading file body.
🎯 Interview Key Takeaway

HEAD checks headers without downloading payload bodies; OPTIONS discovers server capabilities and CORS permissions.

#HTTP Verbs#HEAD#OPTIONS#Beginner
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?