Skip to content

Commit

Permalink
Add get_version endpoint to identify REST API current version
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-aranda committed Dec 20, 2024
1 parent 6896921 commit 8ac6fc0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/narrativelog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
find_messages,
get_configuration,
get_message,
get_version,
)

app = fastapi.FastAPI()
Expand All @@ -27,6 +28,7 @@
subapp.include_router(find_messages.router)
subapp.include_router(get_configuration.router)
subapp.include_router(get_message.router)
subapp.include_router(get_version.router)


@subapp.get("/", response_class=fastapi.responses.HTMLResponse)
Expand Down
27 changes: 27 additions & 0 deletions src/narrativelog/routers/get_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
__all__ = ["get_version"]

import fastapi
import pydantic

from .. import __version__
from ..shared_state import SharedState, get_shared_state

router = fastapi.APIRouter()


class Version(pydantic.BaseModel):
version: str = pydantic.Field(title="Current version of the REST API.")

class Config:
orm_mode = True
from_attributes = True


@router.get("/version", response_model=Version)
@router.get("/version/", response_model=Version, include_in_schema=False)
async def get_version(
state: SharedState = fastapi.Depends(get_shared_state),
) -> Version:
"""Get the current version of the package."""

return Version(version=__version__)

0 comments on commit 8ac6fc0

Please sign in to comment.