Skip to content

Commit

Permalink
[ENH] Added root endpoint with welcome message and API docs link (#286)
Browse files Browse the repository at this point in the history
* Added root endpoint and API docs link

Signed-off-by: samadpls <[email protected]>

* refactored

Signed-off-by: samadpls <[email protected]>

* Reordered import

Signed-off-by: samadpls <[email protected]>

* Added test for root endpoint

Signed-off-by: samadpls <[email protected]>

* Added credentials

Co-authored-by: Alyssa Dai <[email protected]>

---------

Signed-off-by: samadpls <[email protected]>
Co-authored-by: Alyssa Dai <[email protected]>
  • Loading branch information
samadpls and alyssadai committed Mar 21, 2024
1 parent 87a0373 commit eafd493
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
17 changes: 16 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
from fastapi.responses import ORJSONResponse, RedirectResponse
from fastapi.responses import HTMLResponse, ORJSONResponse, RedirectResponse

from .api import utility as util
from .api.routers import attributes, query
Expand All @@ -28,6 +28,21 @@
)


@app.get("/", response_class=HTMLResponse)
def root():
"""
Display a welcome message and a link to the API documentation.
"""
return """
<html>
<body>
<h1>Welcome to the Neurobagel REST API!</h1>
<p>Please visit the <a href="/docs">documentation</a> to view available API endpoints.</p>
</body>
</html>
"""


@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
from app.api import utility as util


def test_root(test_app, set_test_credentials):
"""Given a GET request to the root endpoint, Check for 200 status and expected content."""

with test_app:
response = test_app.get("/")

assert response.status_code == 200
assert "Welcome to the Neurobagel REST API!" in response.text
assert '<a href="/docs">documentation</a>' in response.text


@pytest.mark.parametrize(
"valid_data_element_URI",
["nb:Diagnosis", "nb:Assessment"],
Expand Down

0 comments on commit eafd493

Please sign in to comment.