REST API
Streaming Response
StreamParseValidateHard
What you will learn
- Use Transfer-Encoding: chunked and read incrementally โ loading the full body defeats streaming
- Test early termination โ a client aborting mid-stream must release server resources promptly
- Backpressure: slow consumers must not OOM the server โ measure memory during the stream
Description
Handle streaming responses with Transfer-Encoding: chunked.
Test Scenario
const response = await request.get('/api/v1/stream');
expect(response.headers()['transfer-encoding']).toBe('chunked');
// Process stream
const reader = response.body().getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log('Chunk:', new TextDecoder().decode(value));
}Endpoint
/api/v1/streamTesting Tips
- โขCheck Transfer-Encoding: chunked
- โขProcess chunks as they arrive
- โขHandle stream completion
// 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-streaming-response
2 frameworks available
API Playground
Send requests and inspect responses
Endpoint: /api/v1/stream
Press Enter to send