]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Document UiApiController with ApiController usage 29819/head
authorStephan Müller <smueller@suse.com>
Thu, 22 Aug 2019 12:21:15 +0000 (14:21 +0200)
committerStephan Müller <smueller@suse.com>
Wed, 4 Sep 2019 14:02:11 +0000 (16:02 +0200)
Added documentation how to add an dedicated UI endpoint that uses the 'public' API.

Fixes: https://tracker.ceph.com/issues/41396
Signed-off-by: Stephan Müller <smueller@suse.com>
src/pybind/mgr/dashboard/HACKING.rst

index ef0b16d8b225a7ccdd97c73a8ea30f769e3735b9..2842e5841bef8b88a9da453aa5d399f3438d8a82 100644 (file)
@@ -1054,6 +1054,37 @@ Example:
     def list(self):
       return {"msg": "Hello"}
 
+How to create a dedicated UI endpoint which uses the 'public' API?
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Sometimes we want to combine multiple calls into one single call
+to save bandwidth or for other performance reasons.
+In order to achieve that, we first have to create an ``@UiApiController`` which
+is used for endpoints consumed by the UI but that are not part of the
+'public' API. Let the ui class inherit from the REST controller class.
+Now you can use all methods from the api controller.
+
+Example:
+
+.. code-block:: python
+
+  import cherrypy
+  from . import UiApiController, ApiController, RESTController
+
+
+  @ApiController('ping', secure=False)  # /api/ping
+  class Ping(RESTController):
+    def list(self):
+      return self._list()
+
+    def _list(self):  # To not get in conflict with the JSON wrapper
+      return [1,2,3]
+
+
+  @UiApiController('ping', secure=False)  # /ui-api/ping
+  class PingUi(Ping):
+    def list(self):
+      return self._list() + [4, 5, 6]
 
 How to access the manager module instance from a controller?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~