Skip to main content
skill CX Codex

api-response-optimization · secondsky — Claude Code skill: faster API responses

A coding-agent skill that walks through payload trimming, HTTP caching and compression for API endpoints. Useful when responses feel slow.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill api-response-optimization -a claude-code
Open on GitHub

What api-response-optimization does

The skill covers three areas: sparse fieldsets, HTTP caching and response compression. Each comes with a JavaScript example. Sparse fieldsets let a client ask for specific columns through a fields query parameter. Caching relies on ETag and Cache-Control headers, and a matching if-none-match returns 304 with no body.

Compression is wired up with the compression package, a filter that checks the x-no-compression header and level 6. There is a checklist too: drop unnecessary fields, add ETag/Last-Modified, turn on gzip or brotli, paginate collections, eager-load relations to avoid N+1 queries, and watch metrics through APM tools. Performance targets are listed as well, such as a response under 100ms instead of 500ms.

One piece of advice stands out: profile before optimizing. Skip that step and you may compress the wrong part of the request path while CPU usage climbs. Aggressive caching belongs on immutable resources only; frequently changing data needs a short TTL and cache invalidation on writes.

What it helps with

  • shrink JSON responses by returning only requested fields
  • add ETag support so repeat requests get a 304
  • turn on gzip or brotli for responses over 1KB
  • kill N+1 queries with eager loading
  • build a pre-release checklist for an endpoint

Example prompts for the agent

  • add sparse fieldsets to this endpoint
  • set up ETag and Cache-Control for the product route
  • check these API responses for N+1 and tell me what to cache

How to install api-response-optimization

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill api-response-optimization -a claude-code

2Manually: put the files in place

~/.claude/skills/api-response-optimization/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/api-response-optimization/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about api-response-optimization

How do I install api-response-optimization in Claude?

Run npx skills add secondsky/claude-skills --skill api-response-optimization -a claude-code. The skill file then lands at ~/.claude/skills/api-response-optimization/SKILL.md.

What does api-response-optimization do?

It shows how to cut response payloads, configure HTTP caching and enable compression, with code samples and an optimization checklist.

Which platforms support the skill?

Beyond Claude it installs into Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode, each with its own install command.

Source text

SKILL.md · MIT
---
name: api-response-optimization
description: Optimizes API performance through payload reduction, caching strategies, and compression techniques. Use when improving API response times, reducing bandwidth usage, or implementing efficient caching.
license: MIT
---

# API Response Optimization

Reduce payload sizes, implement caching, and enable compression for faster APIs.

## Sparse Fieldsets

```javascript
// Allow clients to select fields: GET /users?fields=id,name,email
app.get('/users', async (req, res) => {
  const fields = req.query.fields?.split(',') || null;
  const users = await User.find({}, fields?.join(' '));
  res.json(users);
});
```

## HTTP Caching Headers

```javascript
app.get('/products/:id', async (req, res) => {
  const product = await Product.findById(req.params.id);
  const etag = crypto.createHash('md5').update(JSON.stringify(product)).digest('hex');

  if (req.headers['if-none-match'] === etag) {
    return res.status(304).end();
  }

  res.set({
    'Cache-Control': 'public, max-age=3600',
    'ETag': etag
  });
  res.json(product);
});
```

## Response Compression

```javascript
const compression = require('compression');

app.use(compression({
  filter: (req, res) => {
    if (req.headers['x-no-compression']) return false;
    return compression.filter(req, res);
  },
  level: 6  // Balance between speed and compression
}));
```

## Performance Targets

| Metric | Target |
|--------|--------|
| Response time | <100ms (from 500ms) |
| Payload size | <50KB (from 500KB) |
| Server CPU | <30% (from 80%) |

## Optimization Checklist

- [ ] Remove sensitive/unnecessary fields from responses
- [ ] Implement sparse fieldsets
- [ ] Add ETag/Last-Modified headers
- [ ] Enable gzip/brotli compression
- [ ] Use pagination for collections
- [ ] Eager load to prevent N+1 queries
- [ ] Monitor with APM tools

## Best Practices

- Cache immutable resources aggressively
- Use short TTL for frequently changing data
- Invalidate cache on writes
- Compress responses >1KB
- Profile before optimizing

© secondsky · MIT · secondsky/claude-skills

Similar skills

Everything for Backend and APIs →

api-response-optimization by other authors comes first.

From the same set89

mobile-app-debugging A skill for debugging iOS, Android and cross-platform apps: crashes, memory leaks, dropped frames, network problems. CX Codex +1 428installs websocket-implementation A skill that has your agent write the WebSocket server and client: rooms, reconnection, Redis scaling. CX Codex +1 425installs root-cause-tracing Walks an agent backward through the call stack until it finds the original trigger. Useful when an error surfaces deep in execution, not at the entry point. CX Codex +1 426installs recommendation-engine A skill for building recommendation systems: collaborative filtering, matrix factorization, hybrid approaches. Useful for product recommendations and personalization. CX Codex +1 423installs api-filtering-sorting A skill that walks your coding agent through building API filtering and sorting: query parsing, validation, and injection safety. CX Codex +1 418installs bun-drizzle-integration A skill that walks your agent through wiring Drizzle ORM to the bun:sqlite driver: schema, migrations, CRUD and transactions. CX Codex +1 420installs drizzle-orm-d1 A skill that gives your agent working knowledge of Drizzle ORM on Cloudflare D1: schemas, typed queries, Drizzle Kit migrations and the usual D1 errors. CX Codex +1 416installs push-notification-setup A skill that walks your agent through push notification setup with Firebase Cloud Messaging and native services. Useful when you add notifications to an app or debug background messages. CX Codex +1 418installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor