Beispiel #1
0
 def _create_endpoint(
     self, func: Callable, request_type: Union[Type[APIRequest], Type[BaseModel]]
 ) -> Callable:
     """Create a FastAPI endpoint."""
     if isinstance(self.client, AsyncBaseCoreClient):
         return create_async_endpoint(
             func, request_type, response_class=self.response_class
         )
     elif isinstance(self.client, BaseCoreClient):
         return create_sync_endpoint(
             func, request_type, response_class=self.response_class
         )
     raise NotImplementedError
Beispiel #2
0
    def register(self, app: FastAPI) -> None:
        """Register the extension with a FastAPI application.

        Args:
            app: target FastAPI application.

        Returns:
            None
        """
        from titiler.endpoints.stac import stac
        from titiler.templates import templates

        titiler_router = stac.router

        @titiler_router.get("/viewer", response_class=HTMLResponse)
        def stac_demo(request: Request):
            """STAC Viewer."""
            return templates.TemplateResponse(
                name="stac_index.html",
                context={
                    "request": request,
                    "tilejson": request.url_for("tilejson"),
                    "metadata": request.url_for("info"),
                },
                media_type="text/html",
            )

        app.include_router(titiler_router,
                           prefix=self.route_prefix,
                           tags=["Titiler"])

        app.add_api_route(
            name="Get OGC Tiles Resource",
            path="/collections/{collectionId}/items/{itemId}/tiles",
            response_model=TileSetResource,
            response_model_exclude_none=True,
            response_model_exclude_unset=True,
            methods=["GET"],
            endpoint=create_sync_endpoint(self.client.get_item_tiles, ItemUri),
            tags=["OGC Tiles"],
        )
Beispiel #3
0
    def register(self, app: FastAPI) -> None:
        """Register the extension with a FastAPI application.

        Args:
            app: target FastAPI application.

        Returns:
            None
        """
        items_request_model = _create_request_model(Items)

        router = APIRouter()
        router.add_api_route(
            name="Bulk Create Item",
            path="/collections/{collectionId}/bulk_items",
            response_model=str,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["POST"],
            endpoint=create_sync_endpoint(self.client.bulk_item_insert,
                                          items_request_model),
        )
        app.include_router(router, tags=["Bulk Transaction Extension"])