|
| 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 |
0 commit comments