diff --git a/pygeoapi-config.yml b/pygeoapi-config.yml index 14ca540..baac5d9 100644 --- a/pygeoapi-config.yml +++ b/pygeoapi-config.yml @@ -58,11 +58,13 @@ datasets: - CRS84 links: - type: text/csv - description: data - url: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv + rel: canonical + title: data + href: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv - type: text/csv - description: data - url: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv + rel: alternate + title: data + href: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv extents: spatial: bbox: [-180,-90,180,90] @@ -85,11 +87,13 @@ datasets: - CRS84 links: - type: text/html - description: information - url: http://www.naturalearthdata.com/downloads/110m-cultural-vectors/110m-populated-places/ + rel: canonical + title: information + href: http://www.naturalearthdata.com/downloads/110m-cultural-vectors/110m-populated-places/ - type: application/gzip - description: download - url: http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_populated_places_simple.zip + rel: canonical + title: download + href: http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_populated_places_simple.zip extents: spatial: bbox: [-180,-90,180,90] @@ -107,11 +111,9 @@ datasets: - CRS84 links: - type: text/html - description: information - url: http://www.naturalearthdata.com/ - - type: text/html - description: download - url: http://www.naturalearthdata.com/ + rel: canonical + title: information + href: http://www.naturalearthdata.com/ extents: spatial: bbox: [-180,-90,180,90] @@ -134,11 +136,9 @@ datasets: - CRS84 links: - type: text/html - description: information - url: http://www.naturalearthdata.com/ - - type: text/html - description: download - url: http://www.naturalearthdata.com/ + rel: canonical + title: information + href: http://www.naturalearthdata.com/ extents: spatial: bbox: [-180,-90,180,90] diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 50d6dc5..0fc007c 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -35,6 +35,7 @@ import os from jinja2 import Environment, FileSystemLoader from pygeoapi import __version__ +from pygeoapi.log import setup_logger from pygeoapi.provider import load_provider from pygeoapi.provider.base import ProviderConnectionError, ProviderQueryError @@ -59,6 +60,8 @@ class API(object): self.config = config self.config['server']['url'] = self.config['server']['url'].rstrip('/') + setup_logger(config['logging']) + def root(self, headers, args): """ Provide API @@ -131,7 +134,7 @@ class API(object): """ headers_ = { - 'Content-type': 'application/json' + 'Content-type': 'application/openapi+json;version=3.0' } return headers_, 200, json.dumps(openapi) @@ -230,9 +233,10 @@ class API(object): for link in v['links']: lnk = { - 'rel': 'alternate', 'type': link['type'], - 'href': link['url'] + 'rel': link['rel'], + 'title': link['title'], + 'href': link['href'] } collection['links'].append(lnk) @@ -295,6 +299,13 @@ class API(object): try: bbox = args.get('bbox').split(',') + if len(bbox) != 4: + exception = { + 'code': 'InvalidParameterValue', + 'description': 'bbox values should be minx,miny,maxx,maxy' + } + LOGGER.error(exception) + return headers_, 400, json.dumps(exception) except AttributeError: bbox = [] @@ -333,20 +344,30 @@ class API(object): LOGGER.error(exception) return headers_, 500, json.dumps(exception) + prev = startindex - self.config['server']['limit'] next_ = startindex + self.config['server']['limit'] content['links'] = [{ - 'rel': 'self', 'type': 'application/json', + 'rel': 'self', + 'title': 'Collection items', 'href': '/collections/{}/items'.format(dataset) }, { - 'rel': 'next', 'type': 'application/json', + 'rel': 'prev', + 'title': 'items (prev)', + 'href': '/collections/{}/items/?startindex={}'.format(dataset, + prev) + }, { + 'type': 'application/json', + 'rel': 'next', + 'title': 'items (next)', 'href': '/collections/{}/items/?startindex={}'.format(dataset, next_) }, { - 'rel': 'collection', 'type': 'application/json', + 'title': 'Collection', + 'rel': 'collection', 'href': '/collections/{}'.format(dataset) } ] @@ -425,6 +446,5 @@ def _render_j2_template(config, template, data): """ env = Environment(loader=FileSystemLoader(TEMPLATES)) - print(TEMPLATES) template = env.get_template(template) return template.render(config=config, data=data, version=__version__) diff --git a/pygeoapi/flask_app.py b/pygeoapi/flask_app.py index 9f9ca49..afca308 100644 --- a/pygeoapi/flask_app.py +++ b/pygeoapi/flask_app.py @@ -37,7 +37,6 @@ from flask import Flask, make_response, request from flask_cors import CORS from pygeoapi.api import API -from pygeoapi.log import setup_logger APP = Flask(__name__) APP.url_map.strict_slashes = False @@ -134,6 +133,6 @@ def serve(ctx, debug=False): if api_.config['server']['cors']: CORS(APP) - setup_logger(CONFIG['logging']) +# setup_logger(CONFIG['logging']) APP.run(debug=True, host=api_.config['server']['bind']['host'], port=api_.config['server']['bind']['port']) diff --git a/pygeoapi/log.py b/pygeoapi/log.py index 1d6253c..cf02484 100644 --- a/pygeoapi/log.py +++ b/pygeoapi/log.py @@ -44,6 +44,7 @@ def setup_logger(logging_config): log_format = \ '[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s' + date_format = '%Y-%m-%dT%H:%M:%SZ' loglevels = { 'CRITICAL': logging.CRITICAL, @@ -53,20 +54,15 @@ def setup_logger(logging_config): 'DEBUG': logging.DEBUG, 'NOTSET': logging.NOTSET, } - formatter = logging.Formatter(log_format) - log_handler = logging.NullHandler() - - if 'level' in logging_config: - loglevel = loglevels[logging_config['level']] - log_handler = logging.StreamHandler(sys.stdout) + loglevel = loglevels[logging_config['level']] if 'logfile' in logging_config: - log_handler = logging.FileHandler(logging_config['logfile']) + logging.basicConfig(level=loglevel, datefmt=date_format, + format=log_format, filename=logging_config['logfile']) + else: + logging.basicConfig(level=loglevel, datefmt=date_format, + format=log_format, stream=sys.stdout) - log_handler.setLevel(loglevel) - log_handler.setFormatter(formatter) - - LOGGER.addHandler(log_handler) LOGGER.debug('Logging initialized') return diff --git a/pygeoapi/templates/base.html b/pygeoapi/templates/base.html index 9b22cc2..6459da2 100644 --- a/pygeoapi/templates/base.html +++ b/pygeoapi/templates/base.html @@ -14,13 +14,17 @@ + {% for link in data['links'] %} + + {% endfor %} + {% block extrahead %} {% endblock %}