REST API
Field Masking / Sparse Fields
FilterRequestValidateMedium
What you will learn
- Field mask (?fields=id,name) must return ONLY those fields โ extra fields leaking into response defeat the bandwidth win
- Test invalid field names: ?fields=unknown should 400, not silently drop โ dropping masks real typos in client code
- Nested path semantics: ?fields=author.name should return { author: { name } }, not flattened to author_name
Description
Request only specific fields to reduce payload size.
Test Scenario
const response = await request.get('/api/v1/users?fields=id,name');
const body = await response.json();
expect(Object.keys(body.data[0])).toEqual(['id', 'name']);Endpoint
/api/v1/users?fields=id,nameTesting Tips
- โขUse fields query parameter
- โขVerify only requested fields returned
- โขCheck nested field selection
// 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-field-mask
2 frameworks available
API Playground
Send requests and inspect responses
Endpoint: /api/v1/users?fields=id,name
Press Enter to send