I'm using the Loopback REST Client for admin-on-rest successfully with no issues. It's easy to use and works very well for the standard CRUD operations, however I quickly found myself in the need of using non-conventional REST calls like the following:
http://www.remoteurl.com/api/getUsersWithRolesInfo
I also want in some situations to make use of Loopback's in-URL filters, like such:
http://www.remoteurl.com/api/Users?filter=[include][profile]&filter=[include][posts]
How can I achieve this with the <Resource />
component?
Initially I thought of modifying the REST client in order to map the above end points. However the REST client maps its calls to types like GET_ONE
, GET_MANY
, etc.. while what I want to map is an URL (like ../getUserWithRolesInfo
).
Thanks for your help.
You can pass a permanent filter with your List component as well as a one time filter with the ReferenceInput component. For more specific modifications to the call to your API you can use a RestWrapper that will intercept some of the calls to your API and pass the rest to the Loopback Rest Client.
The Loopback REST client does not account for the include filter. You will have to manually construct the URL query. Something like below. Most of this is from the AOR-Loopback Code as is the queryParameters function used below. You can find it all there and modify it to your needs.
function getListQueryConstructor(params, apiResource) {
const page = params.pagination.page
const perPage = params.pagination.perPage
const {field, order} = params.sort
const query = {}
if (params.filter.include) {
query['include'] = params.filter.include
delete params.filter.include
}
query['where'] = {...params.filter}
if (field) {query['order'] = [field + ' ' + order]}
if (perPage > 0) {
query['limit'] = perPage;
if (page >= 0) {
query['skip'] = (page - 1) * perPage
}
}
return (config.host + '/' + apiResource + '?' + queryParameters({filter: JSON.stringify(query)}))
}