api-route-design
Use when designing RESTful API endpoints in FastAPI or Python projects. Triggers for: creating GET/POST/PUT/DELETE endpoints, request validation with Pydantic, response formatting with JSON schemas, status code selection, pagination, filtering, or sorting parameters. NOT for: GraphQL APIs, WebSocket
Оригинален текст · няма потвърден превод на българскиПърво прочетете инструкцията.
Файлът се зарежда от посочения източник само по ваше действие. Можете да го прочетете тук, да го копирате или да го запазите като .md.
GitHub хранилище- Звезди на репото
- 428
- Лиценз
- Не е посочен. Проверете в репозитория.
- Последна проверка на записа
- Няма посочена дата
Добавете в своя инструмент.
Командата отваря избора на skills от репозитория. Прочетете файла и условията на автора преди изпълнение.
npx skills add aiskillstore/marketplaceСтраницата копира текст. Не инсталира и не изпълнява нищо на устройството ви.
Откъс от SKILL.md
Началото на файла на автора, без превод.
API Route Design Skill
Expert design and implementation of RESTful APIs with proper validation, response formatting, and HTTP semantics.
Quick Reference
| Pattern | Example | Purpose |
|---|---|---|
| List resource | @router.get("/fees/", response_model=List[FeeOut]) | Retrieve collection |
| Get by ID | @router.get("/fees/{fee_id}") | Retrieve single resource |
| Create | @router.post("/fees/", response_model=FeeOut, status_code=201) | Create new resource |
| Update | @router.put("/fees/{fee_id}") | Full resource update |
| Patch | @router.patch("/fees/{fee_id}") | Partial resource update |
| Delete | @router.delete("/fees/{fee_id}", status_code=204) | Remove resource |
URL Naming Conventions
/v1/{resource} # Collection endpoints
/v1/{resource}/{id} # Single resource endpoints
/v1/{resource}/{id}/sub # Nested resource endpoints
Rules:
- Use lowercase, hyphens for multi-word:
/student-feesnot/studentFees - Use plural nouns for collections:
/usersnot/user - Use HTTP methods semantically: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)
HTTP Status Codes
| Code | Usage | Example |
|---|---|---|
| 200 | OK | Successful GET, PUT, PATCH |
| 201 | Created | Successful POST (resource created) |
| 202 | Accepted | Async operation started |
| 204 | No Content | Successful DELETE |
| 400 | Bad Request | Invalid input, validation failed |
| 401 | Unauthorized | Missing or invalid auth |
| 403 | Forbidden | Authenticated but not authorized |
| 404 | Not Found | Resource doesn't exist |
| 422 | Unprocessable Entity | Validation errors (Pydantic) |
| 500 | Internal Server Error | Unexpected server error |
Request Validation Patterns
Path Parameters
from fastapi import APIRouter, HTTPException
from typing import Annotated
router = APIRouter()
@router.get("/fees/{fee_id}")
async def get_fee(fee_id: int):
fee = await get_fee_by_id(fee_id)
if not fee:
raise HTTPException(status_code=404, detail="Fee not found")
return fee