Exposing the Icon Theme through the REST API
Hello Devs,
In order to use the icon theme in the Live Data extension (see Loading...), we’d like to introduce a REST endpoint to resolve icons (see Loading...).
The main goal is to allow JavaScript code to use the icons in conformity with the icon theme configurations.
The following endpoints will be introduced:
/xwiki/rest/wikis/{wikiName}/iconThemes/{iconTheme}/icons?icon=icon1&icon=icon2
/xwiki/rest/wikis/{wikiName}/iconThemes/icons?icon=icon1&icon=icon2
The endpoints should be called with the GET
method.
Note: the iconThemes
segment of the endpoints is open to debate and could also be named iconSets
, which is closer to endusers terminology. Let me know which one you prefer (or other propositions of course).
The first one returns the icons metadata for the requested icon theme. The second one returns the icons metadata for the default icon theme.
The response (in json in the example, but jaxb is in charge of rendering in the requested format) is an object with two keys:
- icons: an array of icons metadata object
- missingIcons: an array of requested but not found icon names, this key is not included if all the requested icons are found.
The icons metadata objects has the following keys:
- name: the icon name
- iconSetName: the name of the icon set for which the metadata are resolved
- cssClass: the set of css classes of the icon
- iconSetType:
FONT
if the icons are made from a find,IMAGE
if the icon is an image - url: the url of the icon’s image
The client side is in charge of generating the html required to display the icons according to their metadata.
This endpoint will be available in the newly introduced xwiki-platform-icon-rest
module.
Some examples:
Query1:
/xwiki/rest/wikis/xwiki/iconThemes/icons?icon=add&icon=arrow_undo&icon=unknown
Response1:
{
"icons": [
{
"name": "add",
"iconSetName": "Font Awesome",
"cssClass": "fa fa-plus",
"iconSetType": "FONT",
"url": ""
},
{
"name": "arrow_undo",
"iconSetName": "Font Awesome",
"cssClass": "fa fa-undo",
"iconSetType": "FONT",
"url": ""
}
],
"missingIcons": [
"unknown"
]
}
Query2:
/xwiki/rest/wikis/xwiki/iconThemes/Silk/icons?icon=add&icon=arrow_undo
Response2:
{
"icons": [
{
"name": "add",
"iconSetName": "Silk",
"cssClass": "",
"iconSetType": "IMAGE",
"url": "/resources/icons/silk/add.png?cache-version=1617099790000"
},
{
"name": "arrow_undo",
"iconSetName": "Silk",
"cssClass": "",
"iconSetType": "IMAGE",
"url": "/resources/icons/silk/arrow_undo.png?cache-version=1617099790000"
}
]
}
WDYT?