Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Added root endpoint with welcome message and API docs link #286

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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