diff --git a/src/sciwyrm/main.py b/src/sciwyrm/main.py index fc03735..f0e46a0 100644 --- a/src/sciwyrm/main.py +++ b/src/sciwyrm/main.py @@ -5,6 +5,7 @@ import json from typing import Annotated +import uvicorn from fastapi import Depends, FastAPI, Request, Response from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse @@ -22,10 +23,17 @@ app = FastAPI() -@app.get("/notebook/templates", response_description="Available templates") +@app.get("/livez", response_description="The service is alive") +async def livez() -> str: + """Return 200 if the serve is alive.""" + return "ok" + + +@app.get("/templates", response_description="Available templates") async def list_templates( config: Annotated[AppConfig, Depends(app_config)] ) -> list[notebook.TemplateSummary]: + """Return a list of all available templates.""" """Return a list of available notebook templates.""" return notebook.available_templates(config) @@ -56,7 +64,7 @@ async def template_schema( @app.post("/notebook", response_model=dict, response_description="Rendered notebook") -async def format_notebook( +async def format_notebook_from_json( request: Request, templates: Annotated[Jinja2Templates, Depends(get_templates)], spec: notebook.NotebookSpecWithConfig = Depends(_inject_app_config), # noqa: B008 @@ -70,3 +78,7 @@ async def format_notebook( nb = json.loads(formatted.body) notebook.insert_notebook_metadata(nb, spec) return JSONResponse(nb) + + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0", port=8000)