Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split OGC Features and Tiles endpoints factories #32

Merged
merged 12 commits into from
Mar 16, 2023
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
language_version: python

- repo: https://github.com/PyCQA/isort
rev: 5.4.2
rev: 5.12.0
hooks:
- id: isort
language_version: python
Expand Down
3 changes: 2 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ extra:
nav:
- TiPg: "index.md"
- User Guide:
- "Endpoints": endpoints.md
- "Endpoints documentation": endpoints.md
- "Endpoints Factories": advanced/factories.md
- API:
- db: api/tipg/db.md
- dbmodel: api/tipg/dbmodel.md
Expand Down
160 changes: 160 additions & 0 deletions docs/src/advanced/factories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@

`tipg` creates endpoints using *Endpoint Factories classes* which abstract the definition of input dependency for all the endpoints.

```python
# pseudo code
class Factory:

collection_dependency: Callable

def __init__(self, collection_dependency: Callable):
self.collection_dependency = collection_dependency
self.router = APIRouter()

self.register_routes()

def register_routes(self):

@self.router.get("/collections/{collectionId}")
def collection(
request: Request,
collection=Depends(self.collection_dependency),
):
...

@self.router.get("/collections/{collectionId}/items")
def items(
request: Request,
collection=Depends(self.collection_dependency),
):
...

@self.router.get("/collections/{collectionId}/items/{itemId}")
def item(
request: Request,
collection=Depends(self.collection_dependency),
itemId: str = Path(..., description="Item identifier"),
):
...



# Create FastAPI Application
app = FastAPI()

# Create a Factory instance
endpoints = Factory(collection_dependency=lambda: ["collection1", "collection2"])

# Register the factory router (with the registered endpoints) to the application
app.include_router(endpoints.router)
```

## OGC Features Factory

```python
from tipg.factory import OGCFeaturesFactory

app = FastAPI()
endpoints = OGCFeaturesFactory(full=True)
app.include_router(endpoints.router, tags=["OGC Features API"])
```

#### Creation Options

- **collection_dependency** (Callable[..., tipg.dbmodel.Collection]): Callable which return a Collection instance

- **full** (bool, optional): Create Full OGC Features API set of endpoints (with landing `/` and conformance `/conformance` endpoints). Defaults to `True`

- **router** (fastapi.APIRouter, optional): FastAPI

- **router_prefix** (str, optional): *prefix* for the whole set of endpoints

- **templates** (starlette.templating.Jinja2Templates, optional): Templates to be used in endpoint's responses

#### Endpoints

| Method | Path | Output | Description
| ------ | --------------------------------------------------------------- |-------------------------------------------------- |--------------
| `GET` | `/collections` | HTML / JSON | list of available collections
| `GET` | `/collections/{collectionId}` | HTML / JSON | collection's metadata
| `GET` | `/collections/{collectionId}/queryables` | HTML / SchemaJSON | available queryable for a collection
| `GET` | `/collections/{collectionId}/items` | HTML / JSON / NDJSON / GeoJSON/ GeoJSONSeq / CSV | a set of items for a collection
| `GET` | `/collections/{collectionId}/items/{itemId}` | HTML / JSON/GeoJSON | one collection's item
| `GET` | `/conformance` | HTML / JSON | conformance class landing Page
| `GET` | `/` | HTML / JSON | landing page


## OGC Tiles Factory

```python
from tipg.factory import OGCTilesFactory

app = FastAPI()
endpoints = OGCTilesFactory(full=True)
app.include_router(endpoints.router, tags=["OGC Tiles API"])
```

#### Creation Options

- **collection_dependency** (Callable[..., tipg.dbmodel.Collection]): Callable which return a Collection instance

- **supported_tms** (morecantile.TileMatrixSets): morecantile TileMatrixSets instance (holds a set of TileMatrixSet documents)

- **full** (bool, optional): Create Full OGC Tiles API set of endpoints (with landing `/` and conformance `/conformance` endpoints). Defaults to `True`

- **router** (fastapi.APIRouter, optional): FastAPI

- **router_prefix** (str, optional): *prefix* for the whole set of endpoints

- **templates** (starlette.templating.Jinja2Templates, optional): Templates to be used in endpoint's responses

#### Endpoints

| Method | Path | Output | Description
| ------ | ---------------------------------------------------------------------------------------- |------------------------------ |--------------
| `GET` | `/collections/{collectionId}/tiles[/{TileMatrixSetId}]/{tileMatrix}/{tileCol}/{tileRow}` | Mapbox Vector Tile (Protobuf) | create a web map vector tile from collection's items
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/tilejson.json` | JSON | Mapbox TileJSON document
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/viewer` | HTML | simple map viewer
| `GET` | `/tileMatrixSets` | JSON | list of available TileMatrixSets
| `GET` | `/tileMatrixSets/{tileMatrixSetId}` | JSON | TileMatrixSet document
| `GET` | `/conformance` | HTML / JSON | conformance class landing Page
| `GET` | `/` | HTML / JSON | landing page

## OGC Features + Tile Factory

```python
from tipg.factory import Endpoints

app = FastAPI()
endpoints = Endpoints()
app.include_router(endpoints.router)
```

#### Creation Options

- **collection_dependency** (Callable[..., tipg.dbmodel.Collection]): Callable which return a Collection instance

- **supported_tms** (morecantile.TileMatrixSets): morecantile TileMatrixSets instance (holds a set of TileMatrixSet documents)

- **router** (fastapi.APIRouter, optional): FastAPI

- **router_prefix** (str, optional): *prefix* for the whole set of endpoints

- **templates** (starlette.templating.Jinja2Templates, optional): Templates to be used in endpoint's responses

#### Endpoints

| Method | Path | Output | Description
| ------ | ---------------------------------------------------------------------------------------- |------------------------------ |--------------
| `GET` | `/collections` | HTML / JSON | list of available collections
| `GET` | `/collections/{collectionId}` | HTML / JSON | collection's metadata
| `GET` | `/collections/{collectionId}/queryables` | HTML / SchemaJSON | available queryable for a collection
| `GET` | `/collections/{collectionId}/items` | HTML / JSON / NDJSON / GeoJSON/ GeoJSONSeq / CSV | a set of items for a collection
| `GET` | `/collections/{collectionId}/items/{itemId}` | HTML / JSON/GeoJSON | one collection's item
| `GET` | `/collections/{collectionId}/tiles[/{TileMatrixSetId}]/{tileMatrix}/{tileCol}/{tileRow}` | Mapbox Vector Tile (Protobuf) | create a web map vector tile from collection's items
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/tilejson.json` | JSON | Mapbox TileJSON document
| `GET` | `/collections/{collectionId}[/{TileMatrixSetId}]/viewer` | HTML | simple map viewer
| `GET` | `/tileMatrixSets` | JSON | list of available TileMatrixSets
| `GET` | `/tileMatrixSets/{tileMatrixSetId}` | JSON | TileMatrixSet document
| `GET` | `/conformance` | HTML / JSON | conformance class landing Page
| `GET` | `/` | HTML / JSON | landing page
Loading