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→