我如何从 grails 控制器中使用 restful api?

How can i consume restful api from grails controller?

我已经从手机 company.They 购买了群发短信,前提是我 api documentation.I 可以使用 api 通过 ajax calling.But 对于安全问题,我想从服务器端而不是客户端使用 api。

我已经尝试过 grails.plugins.rest.client.RestBuilder 但没有获得适当的文档。

在我使用的插件依赖中:编译"org.grails.plugins:rest-client-builder:2.1.1"

我想使用来自我的 grails 控制器的 api

这个问题似乎很宽泛。有很多方法可以从任何 JVM 应用程序进行 rest 调用,包括 Grails 应用程序。

一种常见的方法是使用 org.grails:grails-datastore-rest-client 中的 RestBuilder

def rest = new RestBuilder()

// generate a GET request
def response = rest.get('https://someurl.com/someuri')
def json = response.json
def firstName = json.firstName
def lastName = json.lastName
// etc...

// generate a POST request
response = rest.post('https://someurl.com/someuri') {
    // this results in the body of the request being
    // {"firstName":"Jeff","lastName":"Brown"} and
    // the content type being set to application/json
    json {
        firstName = 'Jeff'
        lastName = 'Brown'
    }
}