mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2024-11-26 08:08:19 +01:00
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.
This commit is contained in:
parent
77194707fd
commit
30dc7f1939
@ -4,6 +4,13 @@ import falcon
|
|||||||
db = database_connection()
|
db = database_connection()
|
||||||
db.set_session(readonly=True)
|
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:
|
class AllItemsResource:
|
||||||
def on_get(self, req, resp):
|
def on_get(self, req, resp):
|
||||||
"""Handles GET requests"""
|
"""Handles GET requests"""
|
||||||
@ -64,6 +71,7 @@ class ItemResource:
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
api = application = falcon.API()
|
api = application = falcon.API()
|
||||||
|
api.add_route('/', RootResource())
|
||||||
api.add_route('/items', AllItemsResource())
|
api.add_route('/items', AllItemsResource())
|
||||||
api.add_route('/item/{item_id:int}', ItemResource())
|
api.add_route('/item/{item_id:int}', ItemResource())
|
||||||
|
|
||||||
|
17
dspace_statistics_api/docs/index.html
Normal file
17
dspace_statistics_api/docs/index.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en-US">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>DSpace Statistics API</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>DSpace Statistics API</h1>
|
||||||
|
<p>This site is running the <a href="https://github.com/ilri/dspace-statistics-api" title="DSpace Statistics API project">DSpace Statistics API</a>. The following endpoints are available:</p>
|
||||||
|
<ul>
|
||||||
|
<li>GET <code>/</code> — return a basic API documentation page.</li>
|
||||||
|
<li>GET <code>/items</code> — return views and downloads for all items that Solr knows about¹. Accepts <code>limit</code> and <code>page</code> query parameters for pagination of results.</li>
|
||||||
|
<li>GET <code>/item/id</code> — return views and downloads for a single item (<code>id</code> must be a positive integer). Returns HTTP 404 if an item id is not found.</li>
|
||||||
|
</ul>
|
||||||
|
<p>¹ The API is querying the Solr statistics core, which technically only knows about items that have either views or downloads.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user