Skip to main content
REST API

ETag Caching

CacheRequestValidateHard

What you will learn

  • Send If-None-Match and verify 304 Not Modified โ€” this is how caches stay fresh
  • Test weak vs strong ETags โ€” they compare differently and protect against different bugs
  • Verify ETag changes on every content change โ€” otherwise caches serve stale data

Description

Use ETags for conditional requests and cache validation.

Test Scenario

const response1 = await request.get('/api/v1/etag');
const etag = response1.headers()['etag'];

const response2 = await request.get('/api/v1/etag', {
  headers: { 'If-None-Match': etag }
});
expect(response2.status()).toBe(304);
Endpoint/api/v1/etag

Testing Tips

  • โ€ขGET returns ETag header
  • โ€ขUse If-None-Match for conditional GET
  • โ€ขCheck 304 Not Modified response
// Playwright API Testing - REST
import { 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-etag-caching

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/etag

Press Enter to send