Grails RestBuilder Request Parameters

I am writing some functional tests for the Grails controller, and I feel that it becomes messy when testing query parameters.

I know I can do it, but it just seems awkward.

Map getParms = [id:1, x:foo, y:bar, z:baz]
RestResponse response = builder.get("http://example.com/api/{id}?x={x}&y={y}&z={z}") {
    urlVariables getParams
}

Ideally, I would like to:

  • Fill in the base URL (i.e. identifier) ​​with the argument urlVariablesabove
  • Pass in another query parameter map that adds each as a pair of key values

Sort of:

Map queryParms = [x:foo, y:bar, z:baz]
RestResponse response = builder.get("http://example.com/api/{id}") {
    urlVariables id:1
    queryVariables queryParams
}

I feel it will be much more “DRY” and easier to read / write.

Does anyone know if such a mechanism exists? I know that I could put together a class for this, but I was hoping to avoid this if there is an existing implementation.

+4
source share
2

, .

Map queryParams = [x: 'foo', y: 'bar', z: 'baz']
RestResponse response = builder.get("http://example.com/api/{id}", queryParams) {
    urlVariables id:1
}

RestBuilder's get() , : String url, Map queryParams RequestCustomizer

+3

​​ , API. - :

RestResponse response = builder.get("http://example.com/api/{id}?x={x}&y={y}", [id:1, x:'foo', y:'bar']) 

, , sql groovy SQL

+1

Source: https://habr.com/ru/post/1627366/


All Articles