Sign in
Explore
Prompts · PromptBackend & APIsReviewed

add-endpoint

Prompt to add a REST API endpoint with Pydantic models, a service and a router.

Kind
Prompt
Works with
GitHub Copilot
Languages
Python
Source
microsoft/skills @ 2130750147de
Path
.github/prompts/add-endpoint.prompt.md
License
MIT
Jobs
Implementation
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
# Add API Endpoint

Create a new REST API endpoint following CoreAI DIY patterns.

## Variables

- `RESOURCE_NAME`: The resource name (singular, e.g., `annotation`)
- `RESOURCE_PLURAL`: Plural form (e.g., `annotations`)
- `RESOURCE_DESCRIPTION`: Brief description
- `RESOURCE_FIELDS`: Key fields for the resource

## Steps

### 1. Define Pydantic Models

Create `src/backend/app/models/${RESOURCE_NAME}.py`:

```python
from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field

class ${RESOURCE_NAME.title()}Base(BaseModel):
    """Base model with common fields."""
    # Add ${RESOURCE_FIELDS}
    
    class Config:
        populate_by_name = True

class ${RESOURCE_NAME.title()}Create(${RESOURCE_NAME.title()}Base):
    """Request model for creation."""
    # Add required creation fields
    pass

class ${RESOURCE_NAME.title()}Update(BaseModel):
    """Request model for partial updates (all optional)."""
    # Add optional update fields
    pass

class ${RESOURCE_NAME.title()}(${RESOURCE_NAME.title()}Base):
    """Response model."""
    id: str
    created_at: datetime = Field(..., alias="createdAt")
…