I'm using the Rest Connector in Loopback4 but how would you extend this datasource so that it has options to call more than just 1 url and have more than just 1 function?
Here's my ic.datasource.config.json file:
{
"name": "ic",
"connector": "rest",
"debug": "false",
"options": {
"headers": {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Basic 64 Encoded credentials"
}
},
"operations": [{
"template": {
"method": "GET",
"url": "https://webapi.ic.com/customers/71/jobs/{id}
},
"functions": {
"getDetails": ["id"]
}
}]
}
Here's my ic.service.ts file:
import { getService, juggler } from '@loopback/service-proxy';
import { inject, Provider } from '@loopback/core';
import { icDataSource } from '../datasources/ic.datasource';
export interface icResponseData {
id: string;
title: string;
manager: string;
overview: string;
}
export interface icService {
getDetails(id?: number): Promise<icResponseData>;
}
export class icProvider implements Provider<icService> {
constructor(
// ic must match the name property in the datasource json file
@inject('datasources.ic')
protected dataSource: juggler.DataSource = new icDataSource(),
) {}
value(): Promise<icService> {
return getService(this.dataSource);
}
}