API Filtering & Sorting

SkillSearch

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.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the API Filtering & Sorting skill

What this skill tells your AI

The instructions your AI receives, as published by aj-geddes/useful-ai-prompts in skills/api-filtering-sorting/SKILL.md and read by ahel’s review.

Table of Contents

  • Overview
  • When to Use
  • Quick Start
  • Reference Guides
  • Best Practices

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:

GuideContents
Query Parameter FilteringQuery Parameter Filtering
Advanced Filter ParserAdvanced Filter Parser
Filter Builder PatternFilter Builder Pattern
Python Filtering (SQLAlchemy)Python Filtering (SQLAlchemy)
Elasticsearch FilteringElasticsearch Filtering
Query ValidationQuery 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

Signals

GitHub stars
336
Forks
55
Last commit
Mar 2026
Advanced
Catalog kind
skill
Gateway key
api-filtering-sorting
Source
github.com/aj-geddes/useful-ai-prompts