-
Notifications
You must be signed in to change notification settings - Fork 9
Http
Alex Vigdor edited this page Mar 26, 2018
·
1 revision
http() is a tag function that allows you to perform arbitrary HTTP requests and process the response either synchronously or asynchronously. It is designed with REST APIs in mind, so for example it will automatically parse XML or JSON responses for you by default.
Async PUT with header, parameter, timeout and arbitrary request body, returns Future that can be used to wait for results of async call:
future = http(url:"http://localhost:8080/someEndpoint",method:"PUT",async:true,timeout:5,{
header(name:'foo',value:'bar');
param(name:'x',value:'z');
<~This is the post body~>
})
Synchronous post, serializes map to x-www-form-urlencoded by default, will also automatically deserialize response JSON or XML based on content type
resp = http(method:'POST',url:'http://localhost:28197/mypost',data:['a':'b','c':'d']);
Synchronous post, automatically form-encodes post data based on content type:
resp = http(method:'POST',url:'http://localhost:28197/mypost',data:['a':'b','c':'d'], {
header(name:'Content-Type',value:'application/json')
});
Custom response handler that just returns the status code of a get request
status = http(url:"http://localhost:28197/getme",{
handler({ response -> response.statusLine.statusCode })
})