api-filtering-sorting

Solid

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.

API & Backend 168 stars 27 forks Updated 4 weeks ago MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
74
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# API Filtering & Sorting Build flexible filtering and sorting systems that handle complex queries efficiently. ## Query Parameter Syntax ``` GET /products?category=electronics&price[gte]=100&price[lte]=500&sort=-price,name ``` ## Implementation (Node.js) ```javascript 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; } ``` ## Filter Operators | Operator | Meaning | Example | |----------...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
7 months ago
Last Updated
4 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category