Skip to content

Commit cc9198a

Browse files
committed
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.
1 parent 6f9cc5c commit cc9198a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

roundup/rest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,42 @@ def option_attribute(self, class_name, item_id, attr_name, input):
11661166
)
11671167
return 204, ""
11681168

1169+
@Routing.route("/")
1170+
@_data_decorator
1171+
def describe(self, input):
1172+
"""Describe the rest endpoint"""
1173+
result = {
1174+
"default_version": "1",
1175+
"supported_versions": [ "1" ],
1176+
"links": [ { "uri": self.base_path +"/summary",
1177+
"rel": "summary"},
1178+
{ "uri": self.base_path,
1179+
"rel": "self"},
1180+
{ "uri": self.base_path + "/data",
1181+
"rel": "data"}
1182+
]
1183+
}
1184+
1185+
return 200, result
1186+
1187+
@Routing.route("/data")
1188+
@_data_decorator
1189+
def data(self, input):
1190+
"""Describe the sublements of data
1191+
1192+
FIXME: should have a key for every element under data in
1193+
the schema the user can access.
1194+
This is just an example.
1195+
"""
1196+
result = {
1197+
"issue": { "link": self.base_path + "/data/" + "issue" },
1198+
"status": { "link": self.base_path + "/data/" + "status" },
1199+
"keyword": { "link": self.base_path + "/data/" + "keyword" },
1200+
"user": { "link": self.base_path + "/data/" + "user" }
1201+
}
1202+
1203+
return 200, result
1204+
11691205
@Routing.route("/summary")
11701206
@_data_decorator
11711207
def summary(self, input):

0 commit comments

Comments
 (0)