Skip to content

Commit 377d1e8

Browse files
committed
Add docs on how to add new rest endpoints.
1 parent a40108e commit 377d1e8

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

doc/rest.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,72 @@ Retire/Restore::
192192
>>> r = s.patch(u + 'issue/42', data = d, headers = h)
193193
>>> print(r.json())
194194

195+
Adding new rest endpoints
196+
=========================
197+
198+
Add or edit the file interfaces.py at the root of the tracker
199+
directory.
200+
201+
In that file add (remove indentation):
202+
203+
from roundup.rest import Routing, RestfulInstance, _data_decorator
204+
205+
class RestfulInstance:
206+
207+
@Routing.route("/summary2")
208+
@_data_decorator
209+
def summary2(self, input):
210+
result = { "hello": "world" }
211+
return 200, result
212+
213+
will make a new endpoint .../rest/summary2 that you can test with:
214+
215+
$ curl -X GET .../rest/summary2
216+
{
217+
"data": {
218+
"hello": "world"
219+
}
220+
}
221+
222+
Similarly appending this to interfaces.py after summary2:
223+
224+
@Routing.route("/data/<:class_name>/@schema", 'GET')
225+
def get_element_schema(self, class_name, input):
226+
result = { "schema": {} }
227+
uid = self.db.getuid ()
228+
if not self.db.security.hasPermission('View', uid, class_name) :
229+
raise Unauthorised('Permission to view %s denied' % class_name)
230+
231+
class_obj = self.db.getclass(class_name)
232+
props = class_obj.getprops(protected=False)
233+
schema = result['schema']
234+
235+
for prop in props:
236+
schema[prop] = { "type": repr(class_obj.properties[prop]) }
237+
238+
return result
239+
240+
returns some data about the class
241+
242+
$ curl -X GET .../rest/data/issue/@schema
243+
{
244+
"schema": {
245+
"keyword": {
246+
"type": "<roundup.hyperdb.Multilink to \"keyword\">"
247+
},
248+
"title": {
249+
"type": "<roundup.hyperdb.String>"
250+
},
251+
"files": {
252+
"type": "<roundup.hyperdb.Multilink to \"file\">"
253+
},
254+
"status": {
255+
"type": "<roundup.hyperdb.Link to \"status\">"
256+
}, ...
257+
}
258+
}
259+
260+
195261
Searches and selection
196262
======================
197263

0 commit comments

Comments
 (0)