{"success":true,"name":"trim-and-compress-api-payloads-before-clients-pay-for-the-by","description":"API responses are large and mobile or slow-network clients consume them","category":"ai-brimind","path":"ai-brimind/trim-and-compress-api-payloads-before-clients-pay-for-the-by/SKILL.md","file":"SKILL.md","content":"---\nname: trim-and-compress-api-payloads-before-clients-pay-for-the-by\ndescription: \"API responses are large and mobile or slow-network clients consume them\"\n---\n\n# Trim and Compress API Payloads Before Clients Pay for the Bytes\n\n## When to use\nAn endpoint returns big payloads (long lists, fat objects, embedded blobs), and nobody has checked what the response size costs consumers.\n\n## Example request\nList endpoint embeds each item's full detail object → 3MB to render 20 titles; a slim list shape plus a detail endpoint is the standard split. — Images returned as base64 inside JSON → payload triples in size and can't be cached; URLs to the binary are the mechanism. — Compression never enabled → JSON is highly compressible and the server sends it raw; gzip/brotli at the server or gateway is nearly free. — Client needs 3 fields but gets 40 → mobile users pay data for bytes thrown away; field selection or purpose-built shapes trim it.\n\n## Instructions\nAct as a bandwidth accountant who prices every response in bytes over a bad mobile connection. For heavy endpoints: 1) Measure first — capture a realistic response's actual size (compressed and uncompressed); numbers, not impressions, decide what needs work. 2) Turn on the free win: enable gzip/brotli at the server or gateway if it isn't already — check before assuming; raw JSON over the wire is usually pure waste. 3) Shape by purpose: list views get slim item shapes (the fields the list renders), detail views get the full object — one fat shape serving both is the common bloat pattern. 4) Keep binaries out of JSON: images and files travel as URLs to properly cached resources, never base64 in payloads. 5) Consider field selection (sparse fieldsets, or the query mechanism the API style provides) only if consumers' needs genuinely vary — otherwise purpose-built shapes are simpler than a selection engine. Only conclude once the measured size after changes is confirmed acceptable for the slowest real consumer, and explain how each cut removed bytes the client never used rather than data it needed.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #932\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}