api-filtering-sorting
Implement advanced filtering and sorting capabilities for APIs with query parsing, field validation, and optimization. Use when building search features, complex queries, or flexible data retrieval endpoints.
How do I install this agent skill?
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill api-filtering-sortingIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill provides templates for API filtering and sorting that process untrusted user input into database queries. While it provides best practice advice, some examples contain insecure patterns like unrestricted regex support and dynamic attribute access that could lead to injection or denial-of-service if not carefully implemented.
- Socketwarn
1 alert: gptSecurity
- Snykpass
Risk: LOW · No issues
- Runlayerpass
1/1 file flagged
- ZeroLeakspass
Score: 93/100 · 2 sections analyzed
What does this agent skill do?
API Filtering & Sorting
Table of Contents
Overview
Build flexible filtering and sorting systems that handle complex queries efficiently with proper validation, security, and performance optimization.
When to Use
- Building search and filter interfaces
- Implementing advanced query capabilities
- Creating flexible data retrieval endpoints
- Optimizing query performance
- Validating user input for queries
- Supporting complex filtering logic
Quick Start
Minimal working example:
// Node.js filtering implementation
app.get("/api/products", async (req, res) => {
const filters = {};
const sortOptions = {};
// Parse filtering parameters
const allowedFilters = [
"category",
"minPrice",
"maxPrice",
"inStock",
"rating",
];
for (const key of allowedFilters) {
if (req.query[key]) {
filters[key] = req.query[key];
}
}
// Build MongoDB query
const mongoQuery = {};
if (filters.category) {
mongoQuery.category = filters.category;
}
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Query Parameter Filtering | Query Parameter Filtering |
| Advanced Filter Parser | Advanced Filter Parser |
| Filter Builder Pattern | Filter Builder Pattern |
| Python Filtering (SQLAlchemy) | Python Filtering (SQLAlchemy) |
| Elasticsearch Filtering | Elasticsearch Filtering |
| Query Validation | Query Validation |
Best Practices
✅ DO
- Whitelist allowed filter fields
- Validate all input parameters
- Index fields used for filtering
- Support common operators
- Provide faceted navigation
- Cache filter options
- Limit filter complexity
- Document filter syntax
- Use database-native operators
- Optimize queries with indexes
❌ DON'T
- Allow arbitrary field filtering
- Support unlimited operators
- Ignore SQL injection risks
- Create complex filter logic
- Expose internal field names
- Filter on unindexed fields
- Allow deeply nested filters
- Skip input validation
- Combine all filters with OR
- Ignore performance impact
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/aj-geddes/useful-ai-prompts/api-filtering-sorting">View api-filtering-sorting on skillZs</a>