Skip to content

Commit 69cd3d3

Browse files
Merge pull request #32 from developmentseed/splitEndpointFactories
split OGC Features and Tiles endpoints factories
2 parents 489f024 + 9599bd5 commit 69cd3d3

File tree

6 files changed

+754
-189
lines changed

6 files changed

+754
-189
lines changed

docs/mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extra:
1919
nav:
2020
- TiPg: "index.md"
2121
- User Guide:
22-
- "Endpoints": endpoints.md
22+
- "Endpoints documentation": endpoints.md
23+
- "Endpoints Factories": advanced/factories.md
2324
- API:
2425
- db: api/tipg/db.md
2526
- dbmodel: api/tipg/dbmodel.md

docs/src/advanced/factories.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
2+
`tipg` creates endpoints using *Endpoint Factories classes* which abstract the definition of input dependency for all the endpoints.
3+
4+
```python
5+
# pseudo code
6+
class Factory:
7+
8+
collection_dependency: Callable
9+
10+
def __init__(self, collection_dependency: Callable):
11+
self.collection_dependency = collection_dependency
12+
self.router = APIRouter()
13+
14+
self.register_routes()
15+
16+
def register_routes(self):
17+
18+
@self.router.get("/collections/{collectionId}")
19+
def collection(
20+
request: Request,
21+
collection=Depends(self.collection_dependency),
22+
):
23+
...
24+
25+
@self.router.get("/collections/{collectionId}/items")
26+
def items(
27+
request: Request,
28+
collection=Depends(self.collection_dependency),
29+
):
30+
...
31+
32+
@self.router.get("/collections/{collectionId}/items/{itemId}")
33+
def item(
34+
request: Request,
35+
collection=Depends(self.collection_dependency),
36+
itemId: str = Path(..., description="Item identifier"),
37+
):
38+
...
39+
40+
41+
42+
# Create FastAPI Application
43+
app = FastAPI()
44+
45+
# Create a Factory instance
46+
endpoints = Factory(collection_dependency=lambda: ["collection1", "collection2"])
47+
48+
# Register the factory router (with the registered endpoints) to the application
49+
app.include_router(endpoints.router)
50+
```
51+
52+
## OGC Features API Factory
53+
54+
```python
55+
from tipg.factory import OGCFeaturesFactory
56+
57+
app = FastAPI()
58+
endpoints = OGCFeaturesFactory(with_common=True)
59+
app.include_router(endpoints.router, tags=["OGC Features API"])
60+
```
61+
62+
#### Creation Options
63+
64+
- **collection_dependency** (Callable[..., tipg.dbmodel.Collection]): Callable which return a Collection instance
65+
66+
- **with_common** (bool, optional): Create Full OGC Features API set of endpoints with OGC Common endpoints (landing `/` and conformance `/conformance`). Defaults to `True`
67+
68+
- **router** (fastapi.APIRouter, optional): FastAPI
69+
70+
- **router_prefix** (str, optional): *prefix* for the whole set of endpoints
71+
72+
- **templates** (starlette.templating.Jinja2Templates, optional): Templates to be used in endpoint's responses
73+
74+
- **title** (str, optional): Title of for the endpoints (only used if `with_common=True`)
75+
76+
#### Endpoints
77+
78+
| Method | Path | Output | Description
79+
| ------ | --------------------------------------------------------------- |-------------------------------------------------- |--------------
80+
| `GET` | `/collections` | HTML / JSON | list of available collections
81+
| `GET` | `/collections/{collectionId}` | HTML / JSON | collection's metadata
82+
| `GET` | `/collections/{collectionId}/queryables` | HTML / SchemaJSON | available queryable for a collection
83+
| `GET` | `/collections/{collectionId}/items` | HTML / JSON / NDJSON / GeoJSON/ GeoJSONSeq / CSV | a set of items for a collection
84+
| `GET` | `/collections/{collectionId}/items/{itemId}` | HTML / JSON/GeoJSON | one collection's item
85+
| `GET` | `/conformance` | HTML / JSON | conformance class landing Page
86+
| `GET` | `/` | HTML / JSON | landing page
87+
88+
89+
## OGC Tiles API Factory
90+
91+
```python
92+
from tipg.factory import OGCTilesFactory
93+
94+
app = FastAPI()
95+
endpoints = OGCTilesFactory(with_common=True)
96+
app.include_router(endpoints.router, tags=["OGC Tiles API"])
97+
```
98+
99+
#### Creation Options
100+
101+
- **collection_dependency** (Callable[..., tipg.dbmodel.Collection]): Callable which return a Collection instance
102+
103+
- **supported_tms** (morecantile.TileMatrixSets): morecantile TileMatrixSets instance (holds a set of TileMatrixSet documents)
104+
105+
- **with_common** (bool, optional): Create Full OGC Features API set of endpoints with OGC Common endpoints (landing `/` and conformance `/conformance`). Defaults to `True`
106+
107+
- **router** (fastapi.APIRouter, optional): FastAPI
108+
109+
- **router_prefix** (str, optional): *prefix* for the whole set of endpoints
110+
111+
- **templates** (starlette.templating.Jinja2Templates, optional): Templates to be used in endpoint's responses
112+
113+
- **title** (str, optional): Title of for the endpoints (only used if `with_common=True`)
114+
115+
#### Endpoints
116+
117+
| Method | Path | Output | Description
118+
| ------ | ---------------------------------------------------------------------------------------- |------------------------------ |--------------
119+
| `GET` | `/collections/{collectionId}/tiles[/{TileMatrixSetId}]/{tileMatrix}/{tileCol}/{tileRow}` | Mapbox Vector Tile (Protobuf) | create a web map vector tile from collection's items
120+
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/tilejson.json` | JSON | Mapbox TileJSON document
121+
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/viewer` | HTML | simple map viewer
122+
| `GET` | `/tileMatrixSets` | JSON | list of available TileMatrixSets
123+
| `GET` | `/tileMatrixSets/{tileMatrixSetId}` | JSON | TileMatrixSet document
124+
| `GET` | `/conformance` | HTML / JSON | conformance class landing Page
125+
| `GET` | `/` | HTML / JSON | landing page
126+
127+
## OGC Features + Tiles API Factory
128+
129+
```python
130+
from tipg.factory import Endpoints
131+
132+
app = FastAPI()
133+
endpoints = Endpoints()
134+
app.include_router(endpoints.router)
135+
```
136+
137+
#### Creation Options
138+
139+
- **collection_dependency** (Callable[..., tipg.dbmodel.Collection]): Callable which return a Collection instance
140+
141+
- **supported_tms** (morecantile.TileMatrixSets): morecantile TileMatrixSets instance (holds a set of TileMatrixSet documents)
142+
143+
- **with_common** (bool, optional): Create Full OGC Features API set of endpoints with OGC Common endpoints (landing `/` and conformance `/conformance`). Defaults to `True`
144+
145+
- **router** (fastapi.APIRouter, optional): FastAPI
146+
147+
- **router_prefix** (str, optional): *prefix* for the whole set of endpoints
148+
149+
- **templates** (starlette.templating.Jinja2Templates, optional): Templates to be used in endpoint's responses
150+
151+
- **title** (str, optional): Title of for the endpoints (only used if `with_common=True`)
152+
153+
#### Endpoints
154+
155+
| Method | Path | Output | Description
156+
| ------ | ---------------------------------------------------------------------------------------- |------------------------------ |--------------
157+
| `GET` | `/collections` | HTML / JSON | list of available collections
158+
| `GET` | `/collections/{collectionId}` | HTML / JSON | collection's metadata
159+
| `GET` | `/collections/{collectionId}/queryables` | HTML / SchemaJSON | available queryable for a collection
160+
| `GET` | `/collections/{collectionId}/items` | HTML / JSON / NDJSON / GeoJSON/ GeoJSONSeq / CSV | a set of items for a collection
161+
| `GET` | `/collections/{collectionId}/items/{itemId}` | HTML / JSON/GeoJSON | one collection's item
162+
| `GET` | `/collections/{collectionId}/tiles[/{TileMatrixSetId}]/{tileMatrix}/{tileCol}/{tileRow}` | Mapbox Vector Tile (Protobuf) | create a web map vector tile from collection's items
163+
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/tilejson.json` | JSON | Mapbox TileJSON document
164+
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/viewer` | HTML | simple map viewer
165+
| `GET` | `/tileMatrixSets` | JSON | list of available TileMatrixSets
166+
| `GET` | `/tileMatrixSets/{tileMatrixSetId}` | JSON | TileMatrixSet document
167+
| `GET` | `/conformance` | HTML / JSON | conformance class landing Page
168+
| `GET` | `/` | HTML / JSON | landing page

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ def app(database_url, monkeypatch):
9090
app.user_middleware = []
9191
app.middleware_stack = app.build_middleware_stack()
9292

93-
# register functions to app.state.function_catalog here
94-
9593
with TestClient(app) as app:
9694
yield app
9795

0 commit comments

Comments
 (0)