Към всички skills

api-route-design

aiskillstore · Дизайн

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.

Оригинален SKILL.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

PatternExamplePurpose
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-fees not /studentFees
  • Use plural nouns for collections: /users not /user
  • Use HTTP methods semantically: GET (read), POST (create), PUT/PATCH (update), DELETE (remove)

HTTP Status Codes

CodeUsageExample
200OKSuccessful GET, PUT, PATCH
201CreatedSuccessful POST (resource created)
202AcceptedAsync operation started
204No ContentSuccessful DELETE
400Bad RequestInvalid input, validation failed
401UnauthorizedMissing or invalid auth
403ForbiddenAuthenticated but not authorized
404Not FoundResource doesn't exist
422Unprocessable EntityValidation errors (Pydantic)
500Internal Server ErrorUnexpected 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

Query Parameters (Pagination, Filtering, Sorting)

Целият SKILL.md в GitHub