comparison 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
comparison
equal deleted inserted replaced
5631:a5c890d308c3 5632:a29a8dae2095
1164 "Accept-Patch", 1164 "Accept-Patch",
1165 "application/x-www-form-urlencoded, multipart/form-data" 1165 "application/x-www-form-urlencoded, multipart/form-data"
1166 ) 1166 )
1167 return 204, "" 1167 return 204, ""
1168 1168
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
1169 @Routing.route("/summary") 1205 @Routing.route("/summary")
1170 @_data_decorator 1206 @_data_decorator
1171 def summary(self, input): 1207 def summary(self, input):
1172 """Get a summary of resource from class URI. 1208 """Get a summary of resource from class URI.
1173 1209

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