🎨 CRUD endpoints boilerplate

This commit is contained in:
Brian Wiborg 2025-09-28 17:33:21 +02:00
parent c8206547d8
commit 111a65da85
No known key found for this signature in database

View file

@ -1,17 +1,41 @@
from ohmyapi.router import APIRouter from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
from . import models from . import models
from typing import List
# Expose your app's routes via `router = fastapi.APIRouter`. # Expose your app's routes via `router = fastapi.APIRouter`.
# Use prefixes wisely to avoid cross-app namespace-collisions. # Use prefixes wisely to avoid cross-app namespace-collisions.
# Tags improve the UX of the OpenAPI docs at /docs. # Tags improve the UX of the OpenAPI docs at /docs.
router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}']) router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}'])
@router.get("/")
def hello_world(): @router.get("/")
return { async def list():
"project": "{{ project_name }}", """List all ..."""
"app": "{{ app_name }}", return []
}
@router.post("/")
async def post():
"""Create ..."""
return HTTPException(status_code=HTTPStatus.CREATED)
@router.get("/{id}")
async def get(id: str):
"""Get single ..."""
return {}
@router.put("/{id}")
async def put(id: str):
"""Update ..."""
return HTTPException(status_code=HTTPStatus.ACCEPTED)
@router.delete("/{id}")
async def delete(id: str):
return HTTPException(status_code=HTTPStatus.ACCEPTED)