Skip to content

Commit 1f91f0c

Browse files
authored
Merge pull request #47 from ecmwf-projects/388-landing-page
add landing page
2 parents 8aa974f + 79c8e3b commit 1f91f0c

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

ogc_api_processes_fastapi/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ def include_routers(
3737
fastapi.FastAPI
3838
FastAPI application including OGC API - Processes compliant routes.
3939
"""
40+
landing_page_router = routers.create_landing_page_router(client=client)
41+
app.include_router(landing_page_router)
42+
conformance_declaration_router = routers.create_conformance_declaration_router(
43+
client=client
44+
)
45+
app.include_router(conformance_declaration_router)
4046
processes_router = routers.create_processes_router(client=client)
4147
app.include_router(processes_router)
4248
jobs_router = routers.create_jobs_router(client=client)

ogc_api_processes_fastapi/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ class Link(pydantic.BaseModel):
5151
title: Optional[str] = None
5252

5353

54+
class LandingPage(pydantic.BaseModel):
55+
title: Optional[str] = pydantic.Field(
56+
default=None, example="Example processing server"
57+
)
58+
description: Optional[str] = pydantic.Field(
59+
default=None,
60+
example="Example server implementing the OGC API - Processes 1.0 Standard",
61+
)
62+
links: List[Link]
63+
64+
65+
class ConfClass(pydantic.BaseModel):
66+
conformsTo: List[str] = pydantic.Field(
67+
example="http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/core"
68+
)
69+
70+
5471
class AdditionalParameters(Metadata):
5572
parameters: Optional[List[AdditionalParameter]] = None
5673

ogc_api_processes_fastapi/routers.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,84 @@ def make_links_to_job(
6262
return links
6363

6464

65+
def create_get_landing_page_endpoint(
66+
router: fastapi.APIRouter, client: clients.BaseClient
67+
) -> None:
68+
"""Add the `GET /` endpoint.
69+
70+
Parameters
71+
----------
72+
router : fastapi.APIRouter
73+
Router to which the endpoint should be added.
74+
client : clients.BaseClient
75+
Client implementing the `GET /processes` endpoint.
76+
"""
77+
78+
@router.get(
79+
"/",
80+
response_model=models.LandingPage,
81+
response_model_exclude_none=True,
82+
)
83+
def get_landing_page(request: fastapi.Request) -> models.LandingPage:
84+
"""Get the API landing page."""
85+
links = [
86+
models.Link(
87+
href=urllib.parse.urljoin(str(request.base_url), "openapi.json"),
88+
rel="service-desc",
89+
type="application/vnd.oai.openapi+json;version=3.0",
90+
title="OpenAPI service description",
91+
),
92+
models.Link(
93+
href=urllib.parse.urljoin(str(request.base_url), "conformance"),
94+
rel="http://www.opengis.net/def/rel/ogc/1.0/conformance",
95+
type="application/json",
96+
title="Conformance declaration",
97+
),
98+
models.Link(
99+
href=urllib.parse.urljoin(str(request.base_url), "processes"),
100+
rel="http://www.opengis.net/def/rel/ogc/1.0/processes",
101+
type="application/json",
102+
title="Metadata about the processes",
103+
),
104+
]
105+
landing_page = models.LandingPage(links=links)
106+
107+
return landing_page
108+
109+
110+
def create_get_conformance_endpoint(
111+
router: fastapi.APIRouter, client: clients.BaseClient
112+
) -> None:
113+
"""Add the `GET /conformance` endpoint.
114+
115+
Parameters
116+
----------
117+
router : fastapi.APIRouter
118+
Router to which the endpoint should be added.
119+
client : clients.BaseClient
120+
Client implementing the `GET /conformance` endpoint.
121+
"""
122+
123+
@router.get(
124+
"",
125+
response_model=models.ConfClass,
126+
response_model_exclude_none=True,
127+
)
128+
def get_conformance(request: fastapi.Request) -> models.ConfClass:
129+
"""Get the API conformance declaration page."""
130+
conformance = models.ConfClass(
131+
conformsTo=[
132+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/core",
133+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/ogc-process-description",
134+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/job-list",
135+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/json",
136+
"http://www.opengis.net/spec/ogcapi-processes-1/1.0/conf/oas30",
137+
]
138+
)
139+
140+
return conformance
141+
142+
65143
def create_get_processes_endpoint(
66144
router: fastapi.APIRouter, client: clients.BaseClient
67145
) -> None:
@@ -328,6 +406,52 @@ def get_job_results(job_id: str) -> Dict[str, Any]:
328406
return response
329407

330408

409+
def create_landing_page_router(client: clients.BaseClient) -> fastapi.APIRouter:
410+
"""Register the API router exposing the `/` endpoint.
411+
412+
Parameters
413+
----------
414+
client : clients.BaseClient
415+
Client implementing the API endpoints.
416+
417+
Returns
418+
-------
419+
fastapi.APIRouter
420+
Router exposing the `/` API endpoint.
421+
"""
422+
router = fastapi.APIRouter(
423+
prefix="",
424+
tags=["Capabilities"],
425+
)
426+
create_get_landing_page_endpoint(router=router, client=client)
427+
428+
return router
429+
430+
431+
def create_conformance_declaration_router(
432+
client: clients.BaseClient,
433+
) -> fastapi.APIRouter:
434+
"""Register the API router exposing the `/conformance` endpoint.
435+
436+
Parameters
437+
----------
438+
client : clients.BaseClient
439+
Client implementing the API endpoints.
440+
441+
Returns
442+
-------
443+
fastapi.APIRouter
444+
Router exposing the `/conformance` API endpoint.
445+
"""
446+
router = fastapi.APIRouter(
447+
prefix="/conformance",
448+
tags=["ConformanceDeclaration"],
449+
)
450+
create_get_conformance_endpoint(router=router, client=client)
451+
452+
return router
453+
454+
331455
def create_processes_router(client: clients.BaseClient) -> fastapi.APIRouter:
332456
"""Register the API router collecting the `/processes/...` endpoints.
333457

0 commit comments

Comments
 (0)