Skip to content

Commit 7859298

Browse files
Merge pull request #135 from developmentseed/splitRouteRegistration
split route registration to allow endpoint overriding
2 parents 11b4411 + 9d94ede commit 7859298

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
99
## [unreleased]
1010

1111
- hide map element in HTML pages when collections/items do not have spatial component
12+
- split endpoints registration for more customization
1213

1314
## [0.4.4] - 2023-10-03
1415

tipg/factory.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ def __post_init__(self):
219219
"""Post Init: register route and configure specific options."""
220220
self.register_routes()
221221
if self.with_common:
222-
self.register_common_routes()
222+
self._conformance_route()
223+
self._landing_route()
223224

224225
def url_for(self, request: Request, name: str, **path_params: Any) -> str:
225226
"""Return full url (with prefix) for a specific handler."""
@@ -269,8 +270,8 @@ def links(self, request: Request) -> List[model.Link]:
269270
"""Register factory Routes."""
270271
...
271272

272-
def register_common_routes(self):
273-
"""Register Landing (/) and Conformance (/conformance) routes."""
273+
def _conformance_route(self):
274+
"""Register Conformance (/conformance) route."""
274275

275276
@self.router.get(
276277
"/conformance",
@@ -303,6 +304,9 @@ def conformance(
303304

304305
return data
305306

307+
def _landing_route(self):
308+
"""Register Landing (/) and Conformance (/conformance) routes."""
309+
306310
@self.router.get(
307311
"/",
308312
response_model=model.Landing,
@@ -421,9 +425,15 @@ def links(self, request: Request) -> List[model.Link]:
421425
),
422426
]
423427

424-
def register_routes(self): # noqa: C901
428+
def register_routes(self):
425429
"""Register OGC Features endpoints."""
430+
self._collections_route()
431+
self._collection_route()
432+
self._queryables_route()
433+
self._items_route()
434+
self._item_route()
426435

436+
def _collections_route(self): # noqa: C901
427437
@self.router.get(
428438
"/collections",
429439
response_model=model.Collections,
@@ -603,6 +613,7 @@ def collections( # noqa: C901
603613

604614
return data
605615

616+
def _collection_route(self):
606617
@self.router.get(
607618
"/collections/{collectionId}",
608619
response_model=model.Collection,
@@ -688,6 +699,7 @@ def collection(
688699

689700
return data
690701

702+
def _queryables_route(self):
691703
@self.router.get(
692704
"/collections/{collectionId}/queryables",
693705
response_model=model.Queryables,
@@ -731,6 +743,7 @@ def queryables(
731743

732744
return data
733745

746+
def _items_route(self): # noqa: C901
734747
@self.router.get(
735748
"/collections/{collectionId}/items",
736749
response_class=GeoJSONResponse,
@@ -1005,6 +1018,7 @@ async def items( # noqa: C901
10051018
# Default to GeoJSON Response
10061019
return GeoJSONResponse(data)
10071020

1021+
def _item_route(self):
10081022
@self.router.get(
10091023
"/collections/{collectionId}/items/{itemId}",
10101024
response_class=GeoJSONResponse,
@@ -1247,7 +1261,13 @@ def links(self, request: Request) -> List[model.Link]:
12471261

12481262
def register_routes(self): # noqa: C901
12491263
"""Register OGC Tiles endpoints."""
1264+
self._tilematrixsets_routes()
1265+
self._tilesets_routes()
1266+
self._tile_routes()
1267+
self._tilejson_routes()
1268+
self._stylejson_routes()
12501269

1270+
def _tilematrixsets_routes(self):
12511271
@self.router.get(
12521272
r"/tileMatrixSets",
12531273
response_model=model.TileMatrixSetList,
@@ -1344,6 +1364,7 @@ async def tilematrixset(
13441364

13451365
return data
13461366

1367+
def _tilesets_routes(self):
13471368
@self.router.get(
13481369
"/collections/{collectionId}/tiles",
13491370
response_model=model.TileSetList,
@@ -1547,6 +1568,7 @@ async def collection_tileset(
15471568

15481569
return data
15491570

1571+
def _tile_routes(self):
15501572
@self.router.get(
15511573
"/collections/{collectionId}/tiles/{tileMatrixSetId}/{z}/{x}/{y}",
15521574
response_class=Response,
@@ -1620,6 +1642,8 @@ async def collection_get_tile(
16201642

16211643
return Response(bytes(tile), media_type=MediaType.mvt.value)
16221644

1645+
def _tilejson_routes(self):
1646+
16231647
############################################################################
16241648
# ADDITIONAL ENDPOINTS NOT IN OGC Tiles API (tilejson, style.json, viewer) #
16251649
############################################################################
@@ -1721,6 +1745,7 @@ async def collection_tilejson(
17211745

17221746
return tile_json
17231747

1748+
def _stylejson_routes(self):
17241749
@self.router.get(
17251750
"/collections/{collectionId}/{tileMatrixSetId}/style.json",
17261751
response_model=model.StyleJSON,

0 commit comments

Comments
 (0)