【发布时间】:2020-05-11 20:34:39
【问题描述】:
我在 Loopback4 中使用 Rest 连接器,但您将如何扩展此数据源,以便它可以选择调用不止 1 个 url 并具有不止 1 个函数?
这是我的 ic.datasource.config.json 文件:
{
"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"]
}
}]
}
这是我的 ic.service.ts 文件:
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);
}
}
【问题讨论】:
标签: loopback4