QA
Intermediate LevelREST APIs & Web Services

How does Transfer-Encoding: chunked stream data without knowing content length?

❓ Interview Prompt: Explain `Transfer-Encoding: chunked`, dynamic streaming responses, hex size prefixes, and eliminating `Content-Length` header requirements.

When generating large API responses dynamically (e.g. exporting 500,000 database rows), calculating the total byte size beforehand forces the server to buffer all data in RAM to set 'Content-Length':

'Transfer-Encoding: chunked' Solution:

Allows streaming data in a series of un-buffered chunks:

1
Server omits 'Content-Length' and sets 'Transfer-Encoding: chunked'.
2
Each payload piece is sent as a hex byte size prefix, followed by '

' and chunk data.

3
A zero-length chunk ('0

') signals response completion!

Code Implementation Example

http
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: text/plain

7
Chunk 1
6
Chunk2
0

💡HTTP Transfer-Encoding: chunked raw payload transmission format.
🎯 Interview Key Takeaway

Transfer-Encoding: chunked streams dynamically generated API payloads immediately without buffering entire datasets in server memory.

#Chunked Encoding#Streaming#HTTP#Intermediate
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?