From 30dc7f1939afe9a29c3effa75a6fd8ce8e0702ec Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Thu, 1 Nov 2018 00:19:39 +0200 Subject: [PATCH] Add basic API documentation on root (/) I had imagined plugging in an interactive Swagger or OpenAPI instance here, but that's actually much more involved in Falcon than I want to deal with right now. --- dspace_statistics_api/app.py | 8 ++++++++ dspace_statistics_api/docs/index.html | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 dspace_statistics_api/docs/index.html diff --git a/dspace_statistics_api/app.py b/dspace_statistics_api/app.py index e0eb8b5..4cc6e27 100644 --- a/dspace_statistics_api/app.py +++ b/dspace_statistics_api/app.py @@ -4,6 +4,13 @@ import falcon db = database_connection() db.set_session(readonly=True) +class RootResource: + def on_get(self, req, resp): + resp.status = falcon.HTTP_200 + resp.content_type = 'text/html' + with open('dspace_statistics_api/docs/index.html', 'r') as f: + resp.body = f.read() + class AllItemsResource: def on_get(self, req, resp): """Handles GET requests""" @@ -64,6 +71,7 @@ class ItemResource: cursor.close() api = application = falcon.API() +api.add_route('/', RootResource()) api.add_route('/items', AllItemsResource()) api.add_route('/item/{item_id:int}', ItemResource()) diff --git a/dspace_statistics_api/docs/index.html b/dspace_statistics_api/docs/index.html new file mode 100644 index 0000000..2b41931 --- /dev/null +++ b/dspace_statistics_api/docs/index.html @@ -0,0 +1,17 @@ + + + + + DSpace Statistics API + + +

DSpace Statistics API

+

This site is running the DSpace Statistics API. The following endpoints are available:

+ +

¹ The API is querying the Solr statistics core, which technically only knows about items that have either views or downloads.

+ +