[英]Using loopback-connector-remote to call custom method in another loopback service doesn't create correct URL
我正在嘗試使用loopback-connector-remote數據源連接 2 個環回服務,比如說A和B 。
在B我有這個自定義遠程方法:
/api/B/myModel/myMethod/{id}
如果我訪問B服務上的 API 資源管理器,則此方法工作正常。
然后在A服務上,我想訪問此方法,因此我在遠程模型對象上創建了以下配置(在B 上也相同):
myModel.remoteMethod(
'myMethod',
{
http: {path: '/myMethod/:id', verb: 'get'},
accepts: [
{arg: 'id', type: 'number', required: true}
],
returns: {type: 'object', root: true}
}
);
從A我可以對B進行任何調用,例如 find、findById 等。但是當我調用此自定義方法時,我在A上收到此錯誤:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/1231: Error: id must be a number
查看B中的日志,我看到A正在像這樣調用服務:
strong-remoting:rest-adapter Error in GET /myModel/myMethod/:id?id=1231: Error: id must be a number
為什么在創建 URL 時, strong-remoting或loopback-connector-remote沒有正確替換 id? 我在配置上遺漏了什么嗎?
需要在A服務模型對象的遠程方法配置中添加源路徑:
{ arg: 'id', type: 'number', required: true, http: { source: 'path' }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.