🎨 CRUD endpoints boilerplate
This commit is contained in:
parent
c8206547d8
commit
111a65da85
1 changed files with 31 additions and 7 deletions
|
|
@ -1,17 +1,41 @@
|
|||
from ohmyapi.router import APIRouter
|
||||
from ohmyapi.router import APIRouter, HTTPException, HTTPStatus
|
||||
|
||||
from . import models
|
||||
|
||||
from typing import List
|
||||
|
||||
# Expose your app's routes via `router = fastapi.APIRouter`.
|
||||
# Use prefixes wisely to avoid cross-app namespace-collisions.
|
||||
# Tags improve the UX of the OpenAPI docs at /docs.
|
||||
router = APIRouter(prefix="/{{ app_name }}", tags=['{{ app_name }}'])
|
||||
|
||||
|
||||
@router.get("/")
|
||||
def hello_world():
|
||||
return {
|
||||
"project": "{{ project_name }}",
|
||||
"app": "{{ app_name }}",
|
||||
}
|
||||
|
||||
@router.get("/")
|
||||
async def list():
|
||||
"""List all ..."""
|
||||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue