Skip to content

Commit bcf5448

Browse files
committed
Added background and brief hint to landing page.
1 parent 5e63b0a commit bcf5448

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pip install -r requirements.txt
2121
## Usage
2222

2323
```bash
24-
uvicorn mardi_fdo_server:app --reload --port 8000
24+
uvicorn app.mardi_fdo_server:app --reload --port 8000
2525
```
2626

2727
Request an entity: `curl http://localhost:8000/fdo/Q123456`.

app/mardi_fdo_server.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import httpx
99
from fastapi import FastAPI, HTTPException, Response
10+
from fastapi.responses import HTMLResponse
11+
from fastapi.staticfiles import StaticFiles
1012
from app.mardi_item_helper import BASE_IRI
1113
from fdo_schemas.publication import build_scholarly_article_payload
1214
from fdo_schemas.author import build_author_payload
@@ -20,6 +22,8 @@
2022
version="0.1.0",
2123
)
2224

25+
app.mount("/static", StaticFiles(directory="static"), name="static")
26+
2327

2428
@lru_cache(maxsize=2048)
2529
def fetch_entity(qid: str) -> Dict[str, Any]:
@@ -171,6 +175,58 @@ def to_fdo_minimal(qid: str, entity: Dict[str, Any]) -> Dict[str, Any]:
171175
"schema:Person": to_fdo_author,
172176
}
173177

178+
179+
@app.get("/", response_class=HTMLResponse)
180+
async def root() -> HTMLResponse:
181+
"""Render a greeting with a usage hint on the landing page.
182+
183+
Returns:
184+
HTMLResponse: Greeting and sample FDO link with styled background.
185+
"""
186+
body = """
187+
<html>
188+
<head>
189+
<style>
190+
body {
191+
margin: 0;
192+
padding: 0;
193+
font-family: Arial, sans-serif;
194+
color: #0b132b;
195+
background: url('/static/background_mardi_api.png') no-repeat center center fixed;
196+
background-size: cover;
197+
}
198+
.overlay {
199+
background-color: rgba(255, 255, 255, 0.85);
200+
max-width: 720px;
201+
margin: 12vh auto;
202+
padding: 32px 36px;
203+
border-radius: 12px;
204+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
205+
}
206+
a {
207+
color: #1a73e8;
208+
text-decoration: none;
209+
font-weight: 600;
210+
}
211+
a:hover {
212+
text-decoration: underline;
213+
}
214+
</style>
215+
</head>
216+
<body>
217+
<div class="overlay">
218+
<p>Hello, this is the MaRDI FDO service.</p>
219+
<p>
220+
This API delivers FAIR Digital Object payloads for MaRDI QIDs.
221+
Try <a href="/fdo/Q2055155">/fdo/Q2055155</a>.
222+
</p>
223+
</div>
224+
</body>
225+
</html>
226+
"""
227+
return HTMLResponse(content=body)
228+
229+
174230
@app.get("/fdo/{qid}")
175231
async def get_fdo(qid: str) -> Dict[str, Any]:
176232
"""Return a minimal FDO view for a MaRDI entity."""

0 commit comments

Comments
 (0)