Skip to main content
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/stream

Testing Tips

  • โ€ขCheck Transfer-Encoding: chunked
  • โ€ขProcess chunks as they arrive
  • โ€ขHandle stream completion
// 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-streaming-response

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/stream

Press Enter to send