plugins/api-filtering-sorting/skills/api-filtering-sorting/SKILL.md
Builds flexible API filtering and sorting systems with query parameter parsing, validation, and security. Use when implementing search endpoints, building data grids, or creating dynamic query APIs.
npx skillsauth add secondsky/claude-skills api-filtering-sortingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Build flexible filtering and sorting systems that handle complex queries efficiently.
GET /products?category=electronics&price[gte]=100&price[lte]=500&sort=-price,name
const allowedFilters = ['category', 'status', 'price', 'createdAt'];
const allowedSorts = ['name', 'price', 'createdAt'];
app.get('/products', async (req, res) => {
const filter = {};
const sort = {};
// Parse filters
for (const [key, value] of Object.entries(req.query)) {
if (key === 'sort') continue;
const match = key.match(/^(\w+)\[(\w+)\]$/);
if (match) {
const [, field, operator] = match;
if (!allowedFilters.includes(field)) continue;
filter[field] = { [`$${operator}`]: parseValue(value) };
} else if (allowedFilters.includes(key)) {
filter[key] = value;
}
}
// Parse sort
if (req.query.sort) {
for (const field of req.query.sort.split(',')) {
const direction = field.startsWith('-') ? -1 : 1;
const name = field.replace(/^-/, '');
if (allowedSorts.includes(name)) sort[name] = direction;
}
}
const products = await Product.find(filter).sort(sort);
res.json({ data: products });
});
function parseValue(value) {
if (value === 'true') return true;
if (value === 'false') return false;
if (!isNaN(value)) return Number(value);
return value;
}
| Operator | Meaning | Example |
|----------|---------|---------|
| eq | Equals | ?status=active |
| ne | Not equals | ?status[ne]=deleted |
| gt/gte | Greater than | ?price[gte]=100 |
| lt/lte | Less than | ?price[lte]=500 |
| in | In array | ?status[in]=active,pending |
| like | Contains | ?name[like]=phone |
tools
Use for Bun runtime, bunfig.toml, watch/hot modes, env vars, CLI flags, and module resolution.
data-ai
Use when working with Redis in Bun (ioredis, Upstash), caching, pub/sub, session storage, or key-value operations.
development
Use when building server-rendered React with Bun, including streaming SSR, hydration, renderToString, or custom SSR without a framework.
databases
Bun package manager commands (install, add, remove, update), workspaces, lockfiles, npm/yarn/pnpm migration. Use for dependency management with Bun.