diff roundup/rest.py @ 5632:a29a8dae2095

Initial implementation of function to return data for / and /data endpoints under /rest/. /rest/ returns: 1) default_version of the interface and supported_version array 2) list of links with rel and uri properties that indicate what assets are available under /rest. E.g. /rest/data /data returns: a list of possible assets (e.g. issue, user, keyword, status) and links for accessing those assets. E.G. { "data": { "keyword": { "link": "https://example.net/demo/rest/data/keyword" }, "user": { "link": "https://example.net/demo/rest/data/user" }, ... } } Both of these are currently hand coded. Others will be doing more development on the rest interface. These two examples are meant to spark discussion on what the payloads returned by the rest interface should look like and give some ideas around HATEOAS.
author John Rouillard <rouilj@ieee.org>
date Fri, 01 Mar 2019 23:24:40 -0500
parents a5c890d308c3
children 528b902f98fc
line wrap: on
line diff
--- a/roundup/rest.py	Fri Mar 01 23:16:13 2019 -0500
+++ b/roundup/rest.py	Fri Mar 01 23:24:40 2019 -0500
@@ -1166,6 +1166,42 @@
         )
         return 204, ""
 
+    @Routing.route("/")
+    @_data_decorator
+    def describe(self, input):
+        """Describe the rest endpoint"""
+        result = {
+            "default_version": "1",
+            "supported_versions": [ "1" ],
+            "links": [ { "uri": self.base_path +"/summary",
+                        "rel": "summary"},
+                       { "uri": self.base_path,
+                         "rel": "self"},
+                       { "uri": self.base_path + "/data",
+                         "rel": "data"}
+                   ]
+        }
+
+        return 200, result
+
+    @Routing.route("/data")
+    @_data_decorator
+    def data(self, input):
+        """Describe the sublements of data
+
+           FIXME: should have a key for every element under data in
+                  the schema the user can access.
+           This is just an example.
+        """
+        result = {
+            "issue": { "link": self.base_path + "/data/" + "issue" },
+            "status": { "link": self.base_path + "/data/" + "status" },
+            "keyword": { "link": self.base_path + "/data/" + "keyword" },
+            "user": { "link": self.base_path + "/data/" + "user" }
+        }
+
+        return 200, result
+
     @Routing.route("/summary")
     @_data_decorator
     def summary(self, input):

Roundup Issue Tracker: http://roundup-tracker.org/