diff --git a/eodag/rest/server.py b/eodag/rest/server.py index ee6ffacf8..53aa6a63c 100755 --- a/eodag/rest/server.py +++ b/eodag/rest/server.py @@ -22,7 +22,6 @@ import traceback from contextlib import asynccontextmanager from distutils import dist -from json.decoder import JSONDecodeError from typing import List, Optional, Union import pkg_resources @@ -36,6 +35,7 @@ from pydantic import BaseModel from starlette.exceptions import HTTPException as StarletteHTTPException +from eodag.api.core import DEFAULT_ITEMS_PER_PAGE from eodag.config import load_stac_api_config from eodag.rest.utils import ( QueryableProperty, @@ -308,7 +308,7 @@ class which describes the body of a search request datetime: Union[str, None] = None bbox: Union[list, str, None] = None intersects: Union[dict, None] = None - limit: Union[int, None] = 20 + limit: Union[int, None] = DEFAULT_ITEMS_PER_PAGE page: Union[int, None] = 1 query: Union[dict, None] = None ids: Union[List[str], None] = None @@ -351,8 +351,7 @@ def collections(request: Request): url = request.state.url url_root = request.state.url_root - body = {} - arguments = dict(request.query_params, **body) + arguments = dict(request.query_params) provider = arguments.pop("provider", None) response = get_stac_collections( @@ -371,8 +370,7 @@ def stac_collections_items(collection_id, request: Request): url = request.state.url url_root = request.state.url_root - body = {} - arguments = dict(request.query_params, **body) + arguments = dict(request.query_params) provider = arguments.pop("provider", None) response = search_stac_items( @@ -392,8 +390,7 @@ def collection_by_id(collection_id, request: Request): url = request.state.url_root + "/collections" url_root = request.state.url_root - body = {} - arguments = dict(request.query_params, **body) + arguments = dict(request.query_params) provider = arguments.pop("provider", None) response = get_stac_collection_by_id( @@ -407,14 +404,13 @@ def collection_by_id(collection_id, request: Request): @router.get("/collections/{collection_id}/items/{item_id}", tags=["Data"]) -async def stac_collections_item(collection_id, item_id, request: Request): +def stac_collections_item(collection_id, item_id, request: Request): """STAC collection item by id""" logger.debug(f"URL: {request.url}") url = request.state.url url_root = request.state.url_root - body = {} - arguments = dict(request.query_params, **body) + arguments = dict(request.query_params) provider = arguments.pop("provider", None) response = get_stac_item_by_id( @@ -441,8 +437,7 @@ def stac_collections_item_download(collection_id, item_id, request: Request): """STAC collection item local download""" logger.debug(f"URL: {request.url}") - body = {} - arguments = dict(request.query_params, **body) + arguments = dict(request.query_params) provider = arguments.pop("provider", None) return download_stac_item_by_id_stream( @@ -451,7 +446,7 @@ def stac_collections_item_download(collection_id, item_id, request: Request): @router.get("/catalogs/{catalogs:path}/items", tags=["Data"]) -async def stac_catalogs_items(catalogs, request: Request): +def stac_catalogs_items(catalogs, request: Request): """Fetch catalog's features --- tags: @@ -485,11 +480,8 @@ async def stac_catalogs_items(catalogs, request: Request): logger.debug(f"URL: {request.url}") url = request.state.url url_root = request.state.url_root - try: - body = await request.json() - except JSONDecodeError: - body = {} - arguments = dict(request.query_params, **body) + + arguments = dict(request.query_params) provider = arguments.pop("provider", None) catalogs = catalogs.strip("/").split("/") @@ -505,7 +497,7 @@ async def stac_catalogs_items(catalogs, request: Request): @router.get("/catalogs/{catalogs:path}/items/{item_id}", tags=["Data"]) -async def stac_catalogs_item(catalogs, item_id, request: Request): +def stac_catalogs_item(catalogs, item_id, request: Request): """Fetch catalog's single features --- tags: @@ -542,11 +534,8 @@ async def stac_catalogs_item(catalogs, item_id, request: Request): logger.debug(f"URL: {request.url}") url = request.state.url url_root = request.state.url_root - try: - body = await request.json() - except JSONDecodeError: - body = {} - arguments = dict(request.query_params, **body) + + arguments = dict(request.query_params) provider = arguments.pop("provider", None) catalogs = catalogs.strip("/").split("/") @@ -570,14 +559,11 @@ async def stac_catalogs_item(catalogs, item_id, request: Request): @router.get("/catalogs/{catalogs:path}/items/{item_id}/download", tags=["Data"]) -async def stac_catalogs_item_download(catalogs, item_id, request: Request): +def stac_catalogs_item_download(catalogs, item_id, request: Request): """STAC item local download""" logger.debug(f"URL: {request.url}") - try: - body = await request.json() - except JSONDecodeError: - body = {} - arguments = dict(request.query_params, **body) + + arguments = dict(request.query_params) provider = arguments.pop("provider", None) catalogs = catalogs.strip("/").split("/") @@ -588,7 +574,7 @@ async def stac_catalogs_item_download(catalogs, item_id, request: Request): @router.get("/catalogs/{catalogs:path}", tags=["Capabilities"]) -async def stac_catalogs(catalogs, request: Request): +def stac_catalogs(catalogs, request: Request): """Describe the given catalog and list available sub-catalogs --- tags: @@ -616,11 +602,8 @@ async def stac_catalogs(catalogs, request: Request): logger.debug(f"URL: {request.url}") url = request.state.url url_root = request.state.url_root - try: - body = await request.json() - except JSONDecodeError: - body = {} - arguments = dict(request.query_params, **body) + + arguments = dict(request.query_params) provider = arguments.pop("provider", None) catalogs = catalogs.strip("/").split("/")