‹ 首页

api-filtering-sorting

@aj-geddes · 收录于 5 天前 · 上游提交 4 个月前

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.

适合你,如果正在构建需要灵活过滤和排序的 API 端点。

/ 通过 npx 安装 校验哈希
npx oh-my-skill add aj-geddes/useful-ai-prompts/api-filtering-sorting
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- aj-geddes/useful-ai-prompts/api-filtering-sorting
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify aj-geddes/useful-ai-prompts/api-filtering-sorting
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
300GitHub stars
~492最小装载
~2.6K含声明引用
~2.8K文本包总量
索引托管

怎么用

商店整理自技能原文 · 版本 3f5182c · 表述以原文为准
它做什么

装上后,Claude 会帮你生成 API 的过滤和排序代码——解析查询参数、验证允许的字段、构建数据库查询,并优化性能。

什么时候触发

当你需要给 API 添加搜索、过滤或排序功能,比如构建商品列表的筛选接口时,Claude 就会接入。

装好后可以这样说
Claude 会添加 sort 参数并处理排序逻辑
Claude 会扩展查询参数并验证字段
技能原文 SKILL.md作者撰写 · MIT · 3f5182c

API Filtering & Sorting

Table of Contents
  • [Overview](#overview)
  • [When to Use](#when-to-use)
  • [Quick Start](#quick-start)
  • [Reference Guides](#reference-guides)
  • [Best Practices](#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:

| Guide | Contents | |---|---| | [Query Parameter Filtering](references/query-parameter-filtering.md) | Query Parameter Filtering | | [Advanced Filter Parser](references/advanced-filter-parser.md) | Advanced Filter Parser | | [Filter Builder Pattern](references/filter-builder-pattern.md) | Filter Builder Pattern | | [Python Filtering (SQLAlchemy)](references/python-filtering-sqlalchemy.md) | Python Filtering (SQLAlchemy) | | [Elasticsearch Filtering](references/elasticsearch-filtering.md) | Elasticsearch Filtering | | [Query Validation](references/query-validation.md) | 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
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。