API Fundamentals Course
API Fundamentals
/
Intermediate

Compression

Definition

A technique used by servers to mathematically shrink the size of an API response payload (HTML, JSON, or text) before sending it over the network, dramatically improving load times.

Explain Like I'm New

JSON text is very repetitive. It might contain the word `"firstName"` 10,000 times. Compression algorithms (like Gzip or Brotli) find those repeating words, replace them with tiny symbols, send the tiny file over the internet, and the browser instantly inflates it back to normal.

Real World Example

A backend tries to send a 2 Megabyte JSON file. The server Gzips it down to 150 Kilobytes. The mobile phone downloads 150 KB instantly on a 3G connection and unzips it.

Common Use Cases

  • •Bandwidth saving
  • •Mobile API optimization

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • How does the client tell the server that it is capable of unzipping compressed data?

intermediate

  • Should you use Gzip compression on JPEG images or MP4 videos before sending them from an API?

Flash Cards

Question

How does client tell?

Click to reveal answer
Answer

By sending the `Accept-Encoding` header (e.g., `Accept-Encoding: gzip, deflate, br`).

Question

Compress media?

Click to reveal answer
Answer

No. JPEGs and MP4s are ALREADY highly compressed formats. Trying to Gzip them will waste massive amounts of CPU power on the server and won't shrink the file size at all. Only compress text-based formats (HTML, CSS, JS, JSON, XML).