Skip to content

Commit 4e1f916

Browse files
author
Remco Meeuwissen
committed
Merge remote-tracking branch 'upstream/main'
2 parents ce7e213 + d136d67 commit 4e1f916

File tree

9 files changed

+763
-194
lines changed

9 files changed

+763
-194
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

docs/src/endpoints.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ PathParams:
421421
- **itemId** (str): Feature Id
422422

423423
QueryParams:
424+
424425
- **geom-column** * (str): Select geometry column to create geometry from.
425426
- **bbox-only** * (bool): Only return the bounding box of the feature.
426427
- **simplify** * (float): Simplify the output geometry to given threshold in decimal degrees.
@@ -431,6 +432,8 @@ HeaderParams:
431432

432433
- **accept** (str, one of [`application/geo+json`, `text/html`, `application/json`])): Select response MediaType.
433434

435+
\* **Not in OGC API Features Specification**
436+
434437
Example:
435438

436439
```json
@@ -478,6 +481,7 @@ PathParams:
478481
- **tileRow** (int): TMS's row identifier (Y).
479482

480483
QueryParams:
484+
481485
- **limit** (int): Limits the number of features in the response. Defaults to 10000.
482486
- **bbox** (str): Coma (,) delimited bbox coordinates to spatially filter features in `minx,miny,maxx,maxy` form.
483487
- **datetime** (str): Single datetime or `/` delimited datetime intervals to temporally filter features.
@@ -496,3 +500,5 @@ QueryParams:
496500
- **sortby** (str): Sort the items by a specific column (ascending (default) or descending). argument should be in form of `-/+{column}`.
497501
- **bbox-only** * (bool): Only return the bounding box of the feature.
498502
- **simplify** * (float): Simplify the output geometry to given threshold in decimal degrees.
503+
504+
\* **Not in OGC API Features Specification**

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ dependencies = [
2424
"orjson",
2525
"asyncpg>=0.23.0",
2626
"buildpg>=0.3",
27-
"fastapi>=0.87",
27+
"fastapi>=0.87,<0.95",
2828
"jinja2>=2.11.2,<4.0.0",
2929
"morecantile>=3.1,<4.0",
3030
"geojson-pydantic>=0.4.3",
3131
"pygeofilter>=0.2.0,<0.3.0",
32-
"ciso8601~=2.2.0",
32+
"ciso8601~=2.3",
3333
"starlette-cramjam>=0.3,<0.4",
3434
"importlib_resources>=1.1.0; python_version < '3.9'",
3535
"typing_extensions; python_version < '3.9.2'",

tests/conftest.py

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

96-
# register functions to app.state.function_catalog here
97-
9896
with TestClient(app) as app:
9997
yield app
10098

0 commit comments

Comments
 (0)