使用loopback在URL中获取参数的远程方法

我试图添加一个获取远程方法到我的api使用loopback 2.0为了实现相同的方法结构作为默认的,如:

/myObject/{id} 

我试过的方法是:

  MyObject.remoteMethod( 'remotemethod', { http: { path: '/', verb: 'get' }, accepts: [ {arg: 'id', type: 'string'}, ], returns: { arg: 'status', type: 'string' } } ) 

但它只允许我这样做:

 http://localhost:3000/api/myObject?id=1 

有谁知道我可以做到这一点?

有人也知道我可以如何添加描述到这条路线显示在资源pipe理器中? 文件没有真正说这个..我认为他们的文件不完整,我是唯一一个这样的感觉?

您可以分别注释每个单独的参数。

例如

 MyObject.remoteMethod( 'remotemethod', { http: { path: '/', verb: 'get' }, accepts: [ {arg: 'id', type: 'string', http: {source: query}}, {arg: 'arg2', type: 'anything', http: {source: query}} ...... ], returns: { arg: 'status', type: 'string' } } ) 

答案回环3.0(但我认为它适用于2.0类似)

 MyObject.remoteMethod( 'remotemethod', { description: 'This will insert the description', http: { path: '/:id', verb: 'get' }, accepts: [ {arg: 'id', type: 'number', required: true}, ], returns: { arg: 'status', type: 'string' } } ) 

诀窍是将一个必需的属性添加到您的ID参数,并在path中包含参数。

另请参阅如何添加说明的示例

我不得不同意这些文档还是不完整的。