REST API
API Versioning
RequestValidateTransformMedium
What you will learn
- URL versioning (/v1/) vs header versioning (Accept: vnd.api+json;v=1) โ test both paths if supported
- Version negotiation via Accept header must default gracefully when the header is absent
- Deprecation headers (Sunset, Deprecation) should appear on old versions โ assert their presence
Description
Test different API versions and breaking changes.
Test Scenario
const v1 = await request.get('/api/v1/users/seed-user-2');
const v2 = await request.get('/api/v2/users/seed-user-2');
const v1Body = await v1.json();
const v2Body = await v2.json();
// Breaking change: v1 envelopes as { data: { name } }; v2 returns { user: { fullName } }
expect(v1Body.data.name).toBeDefined();
expect(v2Body.user.fullName).toBeDefined(); // 'name' renamed to 'fullName' in v2Endpoint
/api/v2/usersTesting Tips
- โขCompare v1 and v2 responses
- โขCheck for breaking changes
- โขVerify deprecation headers
// 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-versioning
2 frameworks available
API Playground
Send requests and inspect responses
Endpoint: /api/v2/users
Press Enter to send