【问题标题】:Grails how to write a RESTful post call for my grails application [closed]Grails 如何为我的 Grails 应用程序编写 RESTful 发布调用 [关闭]
【发布时间】:2016-03-02 15:48:23
【问题描述】:

我是编写 RESTful 调用的新手,我也是 Grails 的新手。但是我正在尝试在我的 Grails 应用程序中编写我的第一个 Rest API。

基于此链接: http://grails.github.io/grails-doc/3.0.10/guide/webServices.html#versioningResources

我注意到关于如何发出获取和发布请求的完整说明。

但是,我想通过我的代码而不是通过 culr Unix 工具进行休息后调用。

我应该使用什么? 我正在运行 Grails 3.0.10,我可以使用 HttpBuilder 吗?

你能给我提供例子吗?

【问题讨论】:

    标签: rest grails post restful-url httpbuilder


    【解决方案1】:

    研究 Grails Rest Builder,它是 Grails REST API 的一部分。例如:

    import grails.plugins.rest.client.RestBuilder
    // POST request and get response back
    def resp = new RestBuilder().post("$baseUrl/api/employees/count")
    // confirm that status and returned values are ok
    resp.status == OK.value()
    resp.json.count == 100
    

    groovydocs 在这里:http://springsource.github.io/grails-data-mapping/rest-client/api/index.html。旧文档在这里:https://github.com/grails-plugins/grails-rest-client-builder/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      相关资源
      最近更新 更多