2013-10-14 26 views
9

我对这个网址上运行的服务:http://localhost:8888如何消耗的API在Grails应用

我通过调用它像这样得到这种服务的结果:

http://localhost:8888/colors?colorname=red&shade=dark 

,我得到的结果早在JSON是这样的:

{ 
     "request#": 55, 
     "colorname": "red", 
     "shade": "dark", 
     "available": "No" 
} 

问题

我可以在我的grails应用程序中使用此服务的一些方法是什么?

+0

[REST客户端生成器](HTTP: //grails.org/plugin/rest-client-builder)插件是圆滑的IMO。 – dmahapatro

+0

更好的答案可以在http://stackoverflow.com/questions/25470866/grails-2-4-3-consume-a-rest-service找到。 –

回答

13

假设所有的配置在那里为rest client builder,则最终会与2个 行代码消耗的服务为:

//controller/service/POGO 
def resp = rest.get("http://localhost:8888/colors?colorname=red&shade=dark") 
resp.json //would give the response JSON 

其中

//resources.groovy 
beans = { 
    rest(grails.plugins.rest.client.RestBuilder) 
}