File contents 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
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1 --- 2 name: aj-geddes-useful-ai-prompts-api-filtering-sorting 3 description: API Filtering & Sorting 4 --- 5 6 # API Filtering & Sorting 7 8 ## Table of Contents 9 10 - [Overview](#overview) 11 - [When to Use](#when-to-use) 12 - [Quick Start](#quick-start) 13 - [Reference Guides](#reference-guides) 14 - [Best Practices](#best-practices) 15 16 ## Overview 17 18 Build flexible filtering and sorting systems that handle complex queries efficiently with proper validation, security, and performance optimization. 19 20 ## When to Use 21 22 - Building search and filter interfaces 23 - Implementing advanced query capabilities 24 - Creating flexible data retrieval endpoints 25 - Optimizing query performance 26 - Validating user input for queries 27 - Supporting complex filtering logic 28 29 ## Quick Start 30 31 Minimal working example: 32 33 ```javascript 34 // Node.js filtering implementation 35 app.get("/api/products", async (req, res) => { 36 const filters = {}; 37 const sortOptions = {}; 38 39 // Parse filtering parameters 40 const allowedFilters = [ 41 "category", 42 "minPrice", 43 "maxPrice", 44 "inStock", 45 "rating", 46 ]; 47 for (const key of allowedFilters) { 48 if (req.query[key]) { 49 filters[key] = req.query[key]; 50 } 51 } 52 53 // Build MongoDB query 54 const mongoQuery = {}; 55 56 if (filters.category) { 57 mongoQuery.category = filters.category; 58 } 59 // ... (see reference guides for full implementation) 60 ``` 61 62 ## Reference Guides 63 64 Detailed implementations in the `references/` directory: 65 66 | Guide | Contents | 67 |---|---| 68 | [Query Parameter Filtering](references/query-parameter-filtering.md) | Query Parameter Filtering | 69 | [Advanced Filter Parser](references/advanced-filter-parser.md) | Advanced Filter Parser | 70 | [Filter Builder Pattern](references/filter-builder-pattern.md) | Filter Builder Pattern | 71 | [Python Filtering (SQLAlchemy)](references/python-filtering-sqlalchemy.md) | Python Filtering (SQLAlchemy) | 72 | [Elasticsearch Filtering](references/elasticsearch-filtering.md) | Elasticsearch Filtering | 73 | [Query Validation](references/query-validation.md) | Query Validation | 74 75 ## Best Practices 76 77 ### ✅ DO 78 79 - Whitelist allowed filter fields 80 - Validate all input parameters 81 - Index fields used for filtering 82 - Support common operators 83 - Provide faceted navigation 84 - Cache filter options 85 - Limit filter complexity 86 - Document filter syntax 87 - Use database-native operators 88 - Optimize queries with indexes 89 90 ### ❌ DON'T 91 92 - Allow arbitrary field filtering 93 - Support unlimited operators 94 - Ignore SQL injection risks 95 - Create complex filter logic 96 - Expose internal field names 97 - Filter on unindexed fields 98 - Allow deeply nested filters 99 - Skip input validation 100 - Combine all filters with OR 101 - Ignore performance impact 102 103 --- 104 > Converted and distributed by [TomeVault](https://tomevault.io/claim/aj-geddes) — claim your Tome and manage your conversions. 105 <!-- tomevault:4.0:skill_md:2026-04-11 -->
tomevault-io/skills-registry/tree/main/aj-geddes--useful-ai-prompts--api-filtering-sorting commit 863340a968
Frequently asked questions How do I install the Aj Geddes Useful AI Prompts API Filtering Sorting skill? Run npx skillmds@latest add tomevault-io/aj-geddes-useful-ai-prompts-api-filtering-sorting in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Aj Geddes Useful AI Prompts API Filtering Sorting skill do? API Filtering & Sorting It is listed under Integrations & APIs on SkillMD.
Is Aj Geddes Useful AI Prompts API Filtering Sorting safe to use? This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Aj Geddes Useful AI Prompts API Filtering Sorting? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Aj Geddes Useful AI Prompts API Filtering Sorting free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Aj Geddes Useful AI Prompts API Filtering Sorting? tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.