2017-04-19 21 views
2

的网址,以获取参数我试图添加远程方法获取远程的方法,以达到同样的方法结构作为默认的,如使用2.0环回我的API:使用回环

/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 

是否任意子我知道我能做到这一点吗?

是否有人也知道我可以如何添加描述到这条路线来显示在资源管理器中?文档没有多说这个..我认为他们的文档不完整,我是唯一一个这样认为的人吗?

回答

0

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

例如

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' 
     } 
    } 
) 
1

答案回送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参数,包括帕拉姆在路径中。

也可参见例如如何添加描述

我也不得不承认的文档仍然相当不完善..