I couldn’t find anything related in the docs but I wonder if we can extend or adapt an existing data provider. What I’m trying to achieve is to add or adapt a field to the response.
For example change "url":"http:\/\/localhost:3010\/notes\/in-the-jungle-of-sumatra"
to "slug":"\/notes\/in-the-jungle-of-sumatra"
.
I know I could iterate through the collection or create a new one but maybe there is a more convinient way to tackle this
Given is this code which returns JSON
Kirby::plugin('gearsdigital/kirby-better-link', [
'api' => [
'routes' => [
[
'pattern' => 'better-link/pages',
'method' => 'get',
'action' => function () {
$page = get('page');
$query = get('search', '*');
return site()->search($query, 'title')->paginate([
'page' => $page,
'limit' => 1,
]);
},
],
],
],
]);
Response
{
"code":200,
"data":[
{
"id":"notes\/in-the-jungle-of-sumatra",
"num":20180731,
"title":"In the jungle of Sumatra",
"url":"http:\/\/localhost:3010\/notes\/in-the-jungle-of-sumatra"
},
],
"pagination":{
"page":1,
"total":21,
"offset":0,
"limit":1
},
"status":"ok",
"type":"collection"
}