Back to articles
Your API Responses Are 40x Larger Than They Need to Be

Your API Responses Are 40x Larger Than They Need to Be

via Dev.toPolliog

I was profiling a production API last year when I noticed something that should have been obvious from the start: the response body for a simple list endpoint was 2.4MB. The actual useful data? About 60KB. The rest was a mix of unused fields, redundant nesting, and no compression. It had been that way since day one, and nobody had noticed because on localhost it's fast enough that it doesn't register. This is not a rare situation. It's the default. The Three Ways APIs Bloat Their Responses 1. No Compression This is the easiest win and the most commonly skipped. HTTP has supported gzip compression since 1999. Brotli has been in all major browsers since 2017. Most APIs don't enable either by default. # Check if your API compresses responses curl -s -o /dev/null -w "%{size_download}" https://api.example.com/users curl -s -o /dev/null -w "%{size_download}" -H "Accept-Encoding: gzip" https://api.example.com/users If both numbers are the same, you're not compressing. The fix in Node.js with

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles