API Filtering and Sorting

API Filtering and Sorting

Guides an AI agent to build API filtering and sorting: query parameter parsing, validation, filter builders, and optimisation across MongoDB, SQLAlchemy and Elasticsearch.

Skill files9 files

references/

scripts/

templates/

SKILL.md105 lines
1
---
2
name: api-filtering-sorting
3
description: >
4
Implement advanced filtering and sorting capabilities for APIs with query
5
parsing, field validation, and optimization. Use when building search
6
features, complex queries, or flexible data retrieval endpoints.
7
---
8
9
# API Filtering & Sorting
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Build flexible filtering and sorting systems that handle complex queries efficiently with proper validation, security, and performance optimization.
22
23
## When to Use
24
25
- Building search and filter interfaces
26
- Implementing advanced query capabilities
27
- Creating flexible data retrieval endpoints
28
- Optimizing query performance
29
- Validating user input for queries
30
- Supporting complex filtering logic
31
32
## Quick Start
33
34
Minimal working example:
35
36
```javascript
37
// Node.js filtering implementation
38
app.get("/api/products", async (req, res) => {
39
const filters = {};
40
const sortOptions = {};
41
42
// Parse filtering parameters
43
const allowedFilters = [
44
"category",
45
"minPrice",
46
"maxPrice",
47
"inStock",
48
"rating",
49
];
50
for (const key of allowedFilters) {
51
if (req.query[key]) {
52
filters[key] = req.query[key];
53
}
54
}
55
56
// Build MongoDB query
57
const mongoQuery = {};
58
59
if (filters.category) {
60
mongoQuery.category = filters.category;
61
}
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Query Parameter Filtering](references/query-parameter-filtering.md) | Query Parameter Filtering |
72
| [Advanced Filter Parser](references/advanced-filter-parser.md) | Advanced Filter Parser |
73
| [Filter Builder Pattern](references/filter-builder-pattern.md) | Filter Builder Pattern |
74
| [Python Filtering (SQLAlchemy)](references/python-filtering-sqlalchemy.md) | Python Filtering (SQLAlchemy) |
75
| [Elasticsearch Filtering](references/elasticsearch-filtering.md) | Elasticsearch Filtering |
76
| [Query Validation](references/query-validation.md) | Query Validation |
77
78
## Best Practices
79
80
### ✅ DO
81
82
- Whitelist allowed filter fields
83
- Validate all input parameters
84
- Index fields used for filtering
85
- Support common operators
86
- Provide faceted navigation
87
- Cache filter options
88
- Limit filter complexity
89
- Document filter syntax
90
- Use database-native operators
91
- Optimize queries with indexes
92
93
### ❌ DON'T
94
95
- Allow arbitrary field filtering
96
- Support unlimited operators
97
- Ignore SQL injection risks
98
- Create complex filter logic
99
- Expose internal field names
100
- Filter on unindexed fields
101
- Allow deeply nested filters
102
- Skip input validation
103
- Combine all filters with OR
104
- Ignore performance impact
105

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,690 prompts

More by @OpenSourceBuffGuy

See all
Four city outfit change with depth reference prompt image

Four city outfit change with depth reference

Directs a 12-second vertical video where one woman spins through four city outfit changes, locked to outfit pictures, a face crop and a depth-video motion reference.

video-prompt, reference-image, character-consistency, face-reference, timed-beats, multi-shot, vertical-format, transformation, video-ad, travel, scene-transitions, camera-movement, fashion, cityscape, landmarks, short-form-video, long-form, structured-output, woman, fashion-shoot

Quiet Kyoto autumn travel vlog, 30 seconds prompt image

Quiet Kyoto autumn travel vlog, 30 seconds

Generates a slow, natural 30-second autumn travel vlog in Kyoto of the woman from a reference image, with short casual dialogue, handheld camera and film grain, avoiding an ad look.

video-prompt, vlog, reference-image, character-consistency, handheld, film-grain, home-video, travel, japan, multi-shot, lip-sync, natural-light, guardrails, seedance, for-content-creators, timed-beats, long-form, casual, candid, autumn

Ice heroine fights hunters in Seoul parking garage prompt image

Ice heroine fights hunters in Seoul parking garage

Plans a 30-second supernatural action film where an ice-powered heroine defends a puppy from hunters in a Seoul parking garage, with identity locked to two reference images.

video-prompt, kling, timed-beats, multi-shot, action, martial-arts, visual-effects, character-consistency, reference-image, korea, cityscape, night-scene, slow-motion, tracking-shot, cinematic, creatures, film-score, negative-prompt, dramatic-lighting, neon, advanced, lip-sync, woman

Reviews

Loading reviews…

Discussion

Loading comments…