Prompt file imported from baechul/craft-poc (
.github/prompts/new-api-endpoint.prompt.md). Copyright stays with the author.
Create a new API endpoint for the craft-poc FastAPI application.
Steps
-
Schema (
app/schemas/<resource>.py)- Define Pydantic v2 request and response models using built-in generics.
- All fields must be typed; use
Field(...)with descriptions where helpful.
-
Service (
app/services/<resource>_service.py)- Add an
async defmethod containing the business logic. - If an LLM is involved, use an LCEL pipeline (
|operator) withChatPromptTemplate. - Never hard-code API keys; inject settings via
app/core/.
- Add an
-
Router (
app/api/<resource>.py)- Create an
APIRouterwith an appropriate prefix and tags. - Set
response_modelon every route decorator. - Use
Dependsfor service and settings injection. - Raise
HTTPExceptionfor error cases — no raw dict returns.
- Create an
-
Registration (
app/main.py)- Import the new router and call
app.include_router(...).
- Import the new router and call
-
Tests (
tests/api/test_<resource>.pyandtests/services/test_<resource>_service.py)- Use
pytest+pytest-asyncio. - Mock all LLM / external calls; never hit real APIs.
- Use
Input
Describe the endpoint you need:
- HTTP method and path
- Purpose / business logic
- Request payload fields
- Expected response fields