Skip to content

Commit 674d7f7

Browse files
authored
Add tutorial section for client integration (#14089)
Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com>
1 parent 750ee89 commit 674d7f7

1 file changed

Lines changed: 67 additions & 15 deletions

File tree

  • developer_manual/client_apis/ClientIntegration

developer_manual/client_apis/ClientIntegration/index.rst

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,23 @@ Hooks
4949

5050
Currently only "context-menu" is supported.
5151

52+
.. _endpoint-section:
53+
5254
Endpoint
5355
--------
5456
The endpoint tells the client how the menu entry should look like and how the client can send a request to the server.
5557

5658
Requirements:
57-
- Every text need to be translated by the app
58-
- Current predefined params are fileId and filePath
59-
- {fileId} and {filePath} will be replaced on clients with actual values
60-
- url placeholder are always replaced
61-
- mimetype_filters is a comma-separated list of filters (matches anything that starts with the filter). If there is no filter, the action is shown for every file/folder.
62-
- all urls must be relative
63-
- params is used for body params (currently only POST)
64-
- Icons are always svgs
65-
- Method: supports POST/GET
59+
60+
- Every text need to be translated by the app itself.
61+
- Current predefined params are ``fileId`` and ``filePath``,
62+
- ``{fileId}`` and ``{filePath}`` will be replaced by clients with actual values,
63+
- ``url`` placeholders are always replaced,
64+
- ``mimetype_filters`` is a comma-separated list of filters (matches anything that starts with the filter). If there is no filter, the action is shown for every file/folder.
65+
- All ``urls`` must be relative.
66+
- ``params`` is used for body params (currently only POST).
67+
- ``icon`` field should always provide an SVG.
68+
- ``method`` supports POST/GET.
6669

6770
.. code-block:: javascript
6871
@@ -75,13 +78,13 @@ Requirements:
7578
'icon' => '/apps/abc/img/app.svg'
7679
],
7780
78-
Response
79-
--------
81+
Responses
82+
---------
8083
When clicking on a menu entry the client sends a predefined request to the server.
8184
The app in question can then handle the request and can send two different response types:
8285

83-
Declarative UI
84-
^^^^^^^^^^^^^^
86+
Declarative UI response
87+
^^^^^^^^^^^^^^^^^^^^^^^
8588
The declarative UI response allows the app to send back a new UI to be rendered by the client:
8689
- version: Indicates which version it is. Clients will be backwards compatible. If server sends a newer version than the client can understand the response will be ignored.
8790
- tooltip: Translated text, which will be shown as tooltip / snackbar.
@@ -139,8 +142,8 @@ The tooltip response is a regular DataResponse type, with payload:
139142
}
140143
}
141144
142-
Example:
143-
----------
145+
Example
146+
---------
144147
Here is an example of using the Assistant app.
145148

146149
**Capabilities:**
@@ -207,8 +210,57 @@ When clicking on the action, the client will send a POST request to the specifie
207210
}
208211
}
209212
213+
Develop your first app with client integration
214+
-----------------------------------------------
215+
216+
1. Familiarize yourself on how to create an app via `Develop your first Hello World app <https://cloud.nextcloud.com/s/iyNGp8ryWxc7Efa?dir=%2F%2F2%20Develop%20your%20first%20Hello%20World%20app>`_ for more help on that topic:
217+
218+
2. Create ``Capabilities.php`` in ``/lib`` folder and add to array in ``getCapabilities()``:
219+
220+
.. code-block:: php
221+
222+
'client_integration' => [
223+
'pingpong' => [
224+
'version' => 0.1,
225+
'context-menu' => [
226+
[
227+
'name' => $this->l10n->t('Ping'),
228+
'url' => '/ocs/v2.php/apps/pingpong/ping/{fileId}',
229+
'method' => 'GET',
230+
],
231+
],
232+
],
233+
],
234+
235+
See :ref:`endpoint-section` for endpoint details.
236+
237+
3. Register the app in ``lib/AppInfo/Application.php``
238+
239+
.. code-block:: php
240+
241+
public function register(IRegistrationContext $context): void {
242+
$context->registerCapability(Capabilities::class);
243+
}
244+
245+
4. Add consuming function in ``/lib/Controller/ApiController.php``:
246+
247+
.. code-block:: php
248+
249+
#[NoAdminRequired]
250+
#[ApiRoute(verb: 'GET', url: '/ping/{fileId}')]
251+
public function ping(int $fileId = 1): DataResponse {
252+
return new DataResponse(
253+
['version' => 0.1,
254+
'tooltip' => $this->l10n->t("Pong file %s", $fileId)]
255+
);
256+
}
257+
258+
5. Response is ``DataResponse`` with a version (currently 0.1) and a translated tooltip.
259+
210260
Issues/Bugs
211261
-----------
212262

213263
Please report issues, bugs or feature requests at https://github.com/nextcloud/files-clients with label "Client integration".
214264

265+
266+

0 commit comments

Comments
 (0)