REST API
HEAD Request
RequestCacheValidateMedium
What you will learn
- HEAD must return identical headers to GET โ but zero body. Any body is a spec violation
- Use HEAD to pre-check resource existence without downloading โ cheap for large resources
- Content-Length, ETag, Last-Modified must be present if GET would set them
Description
Use HEAD to check resource existence without body. Verify headers only.
Test Scenario
const response = await request.head('/api/v1/users/1');
expect(response.status()).toBe(200);
expect(response.headers()['content-length']).toBeDefined();Endpoint
/api/v1/users/:idTesting Tips
- โขHEAD returns headers only, no body
- โขCheck Content-Length header
- โขUse for cache validation
// Playwright API Testing - RESTimport { test, expect } from '@playwright/test';test('REST API request', async ({ request }) => {const response = await request.get('/api/v1/resource');expect(response.ok()).toBeTruthy();expect(response.status()).toBe(200);const data = await response.json();expect(data).toBeDefined();});
Challenge ID: rest-head-request
2 frameworks available
API Playground
Send requests and inspect responses
Endpoint: /api/v1/users/:id
Press Enter to send