Skip to content

feat: API response compression & payload optimization#581

Open
mendarb wants to merge 1 commit intorohitdash08:mainfrom
mendarb:feat/api-compression-129
Open

feat: API response compression & payload optimization#581
mendarb wants to merge 1 commit intorohitdash08:mainfrom
mendarb:feat/api-compression-129

Conversation

@mendarb
Copy link

@mendarb mendarb commented Mar 20, 2026

Summary

  • Adds gzip/brotli compression via flask-compress middleware for all API responses
  • Strips null fields from JSON payloads to reduce response size
  • Adds ETag headers with If-None-Match support, returning 304 Not Modified when content hasn't changed
  • Adds X-Original-Size / X-Compressed-Size response headers for measuring size reduction
  • Adds pagination metadata (data + pagination envelope) to all list endpoints: /expenses, /bills, /categories, /reminders
  • Includes a reusable paginate_query() helper and parse_pagination_args() utility

Closes #129

Changes

File What
app/compression.py New module: compression init, null stripping, ETag, pagination helpers
app/__init__.py Wire in flask-compress and optimize_json_response after_request hook
app/routes/expenses.py Paginated response envelope for GET /expenses
app/routes/bills.py Paginated response envelope for GET /bills
app/routes/categories.py Paginated response envelope for GET /categories
app/routes/reminders.py Paginated response envelope for GET /reminders
requirements.txt Add flask-compress==1.15
tests/test_compression.py 11 new tests for ETags, null stripping, gzip, pagination
Existing test files Updated to use response["data"] instead of bare list

Test plan

  • ETags present on JSON responses
  • Conditional GET returns 304 when ETag matches
  • Null fields stripped from JSON output
  • X-Original-Size / X-Compressed-Size headers present
  • gzip-compressed responses decode correctly
  • All list endpoints return {data: [...], pagination: {...}} envelope
  • Custom page / page_size params respected
  • Existing tests updated and passing

🤖 Generated with Claude Code

- Add gzip/brotli compression via flask-compress middleware
- Strip null fields from JSON responses to reduce payload size
- Add ETag headers with If-None-Match support for 304 responses
- Add X-Original-Size / X-Compressed-Size headers for observability
- Add paginated responses (data + pagination metadata) to all list endpoints
- Update existing tests for new paginated response format

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mendarb mendarb requested a review from rohitdash08 as a code owner March 20, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API response compression & payload optimization

1 participant