minor cleanup of Flask/Starlette (#490)

This commit is contained in:
Tom Kralidis
2020-07-13 07:44:53 -04:00
committed by GitHub
parent 28157426f5
commit 86afe73a9b
2 changed files with 85 additions and 64 deletions
+35 -28
View File
@@ -90,9 +90,9 @@ if (OGC_SCHEMAS_LOCATION is not None and
@APP.route('/')
def root():
def landing_page():
"""
HTTP root content of pygeoapi. Intro page access point
OGC API landing page endpoint
:returns: HTTP response
"""
@@ -109,7 +109,7 @@ def root():
@APP.route('/openapi')
def openapi():
"""
OpenAPI access point
OpenAPI endpoint
:returns: HTTP response
"""
@@ -130,7 +130,7 @@ def openapi():
@APP.route('/conformance')
def conformance():
"""
OGC open api conformance access point
OGC API conformance endpoint
:returns: HTTP response
"""
@@ -147,18 +147,18 @@ def conformance():
@APP.route('/collections')
@APP.route('/collections/<name>')
def describe_collections(name=None):
@APP.route('/collections/<collection_id>')
def describe_collections(collection_id=None):
"""
OGC open api collections access point
OGC API collections endpoint
:param name: identifier of collection name
:param collection_id: collection identifier
:returns: HTTP response
"""
headers, status_code, content = api_.describe_collections(
request.headers, request.args, name)
request.headers, request.args, collection_id)
response = make_response(content, status_code)
@@ -168,18 +168,18 @@ def describe_collections(name=None):
return response
@APP.route('/collections/<name>/queryables')
def get_collection_queryables(name=None):
@APP.route('/collections/<collection_id>/queryables')
def get_collection_queryables(collection_id=None):
"""
OGC open api collections querybles access point
OGC API collections querybles endpoint
:param name: identifier of collection name
:param collection_id: collection identifier
:returns: HTTP response
"""
headers, status_code, content = api_.get_collection_queryables(
request.headers, request.args, name)
request.headers, request.args, collection_id)
response = make_response(content, status_code)
@@ -193,7 +193,10 @@ def get_collection_queryables(name=None):
@APP.route('/collections/<collection_id>/items/<item_id>')
def dataset(collection_id, item_id=None):
"""
OGC open api collections/{dataset}/items/{item} access point
OGC API collections items endpoint
:param collection_id: collection identifier
:param item_id: item identifier
:returns: HTTP response
"""
@@ -216,7 +219,7 @@ def dataset(collection_id, item_id=None):
@APP.route('/stac')
def stac_catalog_root():
"""
STAC access point
STAC root endpoint
:returns: HTTP response
"""
@@ -235,7 +238,9 @@ def stac_catalog_root():
@APP.route('/stac/<path:path>')
def stac_catalog_path(path):
"""
STAC access point
STAC path endpoint
:param path: path
:returns: HTTP response
"""
@@ -252,16 +257,17 @@ def stac_catalog_path(path):
@APP.route('/processes')
@APP.route('/processes/<name>')
def describe_processes(name=None):
@APP.route('/processes/<process_id>')
def describe_processes(process_id=None):
"""
OGC open api processes access point (experimental)
OGC API - Processes description endpoint
:param process_id: process identifier
:param name: identifier of process to describe
:returns: HTTP response
"""
headers, status_code, content = api_.describe_processes(
request.headers, request.args, name)
request.headers, request.args, process_id)
response = make_response(content, status_code)
@@ -271,12 +277,13 @@ def describe_processes(name=None):
return response
@APP.route('/processes/<name>/jobs', methods=['GET', 'POST'])
def execute_process(name=None):
@APP.route('/processes/<process_id>/jobs', methods=['GET', 'POST'])
def execute_process(process_id=None):
"""
OGC open api jobs from processes access point (experimental)
OGC API - Processes jobs endpoint
:param process_id: process identifier
:param name: identifier of process to execute
:returns: HTTP response
"""
@@ -284,7 +291,7 @@ def execute_process(name=None):
headers, status_code, content = ({}, 200, "[]")
elif request.method == 'POST':
headers, status_code, content = api_.execute_process(
request.headers, request.args, request.data, name)
request.headers, request.args, request.data, process_id)
response = make_response(content, status_code)
@@ -304,8 +311,8 @@ def serve(ctx, server=None, debug=False):
:param server: `string` of server type
:param debug: `bool` of whether to run in debug mode
:returns void
:returns: void
"""
# setup_logger(CONFIG['logging'])
+50 -36
View File
@@ -72,11 +72,13 @@ api_ = API(CONFIG)
@app.route('/')
async def root(request: Request):
async def landing_page(request: Request):
"""
HTTP root content of pygeoapi. Intro page access point
OGC API landing page endpoint
:returns: Starlette HTTP Response
"""
headers, status_code, content = api_.root(
request.headers, request.query_params)
@@ -91,10 +93,11 @@ async def root(request: Request):
@app.route('/openapi/')
async def openapi(request: Request):
"""
OpenAPI access point
OpenAPI endpoint
:returns: Starlette HTTP Response
"""
with open(os.environ.get('PYGEOAPI_OPENAPI'), encoding='utf8') as ff:
openapi = yaml_load(ff)
@@ -112,7 +115,7 @@ async def openapi(request: Request):
@app.route('/conformance/')
async def conformance(request: Request):
"""
OGC open api conformance access point
OGC API conformance endpoint
:returns: Starlette HTTP Response
"""
@@ -129,20 +132,21 @@ async def conformance(request: Request):
@app.route('/collections')
@app.route('/collections/')
@app.route('/collections/{name}')
@app.route('/collections/{name}/')
async def describe_collections(request: Request, name=None):
@app.route('/collections/{collection_id}')
@app.route('/collections/{collection_id}/')
async def describe_collections(request: Request, collection_id=None):
"""
OGC open api collections access point
OGC API collections endpoint
:param collection_id: collection identifier
:param name: identifier of collection name
:returns: Starlette HTTP Response
"""
if 'name' in request.path_params:
name = request.path_params['name']
if 'collection_id' in request.path_params:
collection_id = request.path_params['collection_id']
headers, status_code, content = api_.describe_collections(
request.headers, request.query_params, name)
request.headers, request.query_params, collection_id)
response = Response(content=content, status_code=status_code)
if headers:
@@ -151,21 +155,21 @@ async def describe_collections(request: Request, name=None):
return response
@app.route('/collections/{name}/queryables')
@app.route('/collections/{name}/queryables/')
async def get_collection_queryables(request: Request, name=None):
@app.route('/collections/{collection_id}/queryables')
@app.route('/collections/{collection_id}/queryables/')
async def get_collection_queryables(request: Request, collection_id=None):
"""
OGC open api collections queryables access point
OGC API collections queryables endpoint
:param name: identifier of collection name
:param collection_id: collection identifier
:returns: Starlette HTTP Response
"""
if 'name' in request.path_params:
name = request.path_params['name']
if 'collection_id' in request.path_params:
collection_id = request.path_params['collection_id']
headers, status_code, content = api_.get_collection_queryables(
request.headers, request.query_params, name)
request.headers, request.query_params, collection_id)
response = Response(content=content, status_code=status_code)
if headers:
@@ -180,7 +184,10 @@ async def get_collection_queryables(request: Request, name=None):
@app.route('/collections/{collection_id}/items/{item_id}/')
async def dataset(request: Request, collection_id=None, item_id=None):
"""
OGC open api collections/{dataset}/items/{item_id} access point
OGC API collections items endpoint
:param collection_id: collection identifier
:param item_id: item identifier
:returns: Starlette HTTP Response
"""
@@ -208,7 +215,8 @@ async def dataset(request: Request, collection_id=None, item_id=None):
@app.route('/stac')
async def stac_catalog_root(request: Request):
"""
STAC access point
STAC root endpoint
:returns: Starlette HTTP response
"""
@@ -226,7 +234,10 @@ async def stac_catalog_root(request: Request):
@app.route('/stac/{path:path}')
async def stac_catalog_path(request: Request):
"""
STAC access point
STAC endpoint
:param path: path
:returns: Starlette HTTP response
"""
@@ -245,17 +256,18 @@ async def stac_catalog_path(request: Request):
@app.route('/processes')
@app.route('/processes/')
@app.route('/processes/{name}')
@app.route('/processes/{name}/')
async def describe_processes(request: Request, name=None):
@app.route('/processes/{process_id}')
@app.route('/processes/{process_id}/')
async def describe_processes(request: Request, process_id=None):
"""
OGC open api processes access point (experimental)
OGC API - Processes description endpoint
:param process_id: identifier of process to describe
:param name: identifier of process to describe
:returns: Starlette HTTP Response
"""
headers, status_code, content = api_.describe_processes(
request.headers, request.query_params, name)
request.headers, request.query_params, process_id)
response = Response(content=content, status_code=status_code)
@@ -265,13 +277,14 @@ async def describe_processes(request: Request, name=None):
return response
@app.route('/processes/{name}/jobs', methods=['GET', 'POST'])
@app.route('/processes/{name}/jobs/', methods=['GET', 'POST'])
async def execute_process(request: Request, name=None):
@app.route('/processes/{process_id}/jobs', methods=['GET', 'POST'])
@app.route('/processes/{process_id}/jobs/', methods=['GET', 'POST'])
async def execute_process(request: Request, process_id=None):
"""
OGC open api jobs from processes access point (experimental)
OGC API - Processes jobs endpoint
:param process_id: identifier of process to execute
:param name: identifier of process to execute
:returns: Starlette HTTP Response
"""
@@ -279,7 +292,7 @@ async def execute_process(request: Request, name=None):
headers, status_code, content = ({}, 200, "[]")
elif request.method == 'POST':
headers, status_code, content = api_.execute_process(
request.headers, request.query_params, request.data, name)
request.headers, request.query_params, request.data, process_id)
response = Response(content=content, status_code=status_code)
@@ -299,7 +312,8 @@ def serve(ctx, server=None, debug=False):
:param server: `string` of server type
:param debug: `bool` of whether to run in debug mode
:returns void
:returns: void
"""
# setup_logger(CONFIG['logging'])