
Api Filtering Sorting
Handles the common pattern of turning URL query parameters into database filters and sorts, with built-in security through field whitelisting. The implementation shows MongoDB-style operators (gte, lte, in, like) parsed from bracket syntax like price[gte]=100, plus multi-field sorting with direction indicators. Worth noting it includes type coercion for booleans and numbers, which saves you from string comparison bugs. The security model is straightforward: explicitly allow which fields can be filtered or sorted, then validate everything else. If you're building any kind of search or list endpoint, this gives you a solid starting point that's more thought-through than what you'd probably write in fifteen minutes.
- skills.sh installs
- 432
- GitHub stars
- 248
- last updated
- Aug 21, 2026
Install
$ npx -y skills add secondsky/claude-skills --skill api-filtering-sorting --agent claude-codeInstalls into .claude/skills of the current project.
Files
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)
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;
}
}
Sponsors
Details
- Repository
- github.com/secondsky/claude-skills
- Categories
- Backend & APIs, Security
- First seen
- Jun 3, 2026
More from secondsky/claude-skills
All 146- Defense In Depth Validation430
- Session Management427
- Ultracite426
- Nuxt Production425
- Api Gateway Configuration422
- Oauth Implementation422
- Nuxt Ui V4421
- Health Check Endpoints420
- Cloudflare D1416
- Api Changelog Versioning415
- Dependency Upgrade415
- Idempotency Handling415
- Nuxt Server415
- Turborepo414
- Mobile Offline Support412
- Recommendation System412
- Api Versioning Strategy410
- Claude Code Bash Patterns408
- Claude Hook Writer408
- Logging Best Practices408
- Cloudflare Manager407
- Plan Interview406
- Ml Pipeline Automation402
- Nuxt Core401