Package com.avoka.tm.http
Provides HTTP Client classes using underlying Apache HTTP Components library.
The example below performs REST request and returns a Path object.
import com.avoka.tm.http.*
import com.avoka.tm.util.*
Map params = [:]
params.id = request.getParameter('customerId')
params.account = request.getParameter('accountId')
String username = svcDef.paramsMap.username
String password = svcDef.paramsMap.password
// execute GET request and return a HttpResponse object
HttpResponse response = new GetRequest('https://service.mycorp.com/secure/rest/accounts/')
.setParams(params)
.setBasicAuth(username, password)
.execute()
if (response.isStatusOK()) {
// get JSON object from the response
Path path = response.getPathContent()
...
} else if (response.isStatusNotFound()) {
// object not found
...
} else {
throw new RuntimeException(response.statusLine)
}
The example below performs POST request and converts the response into a Path document.
import com.avoka.tm.http.*
import com.avoka.tm.util.*
String message = '''{
"name":"John Doe",
"email":"[email protected]",
"age":42
}'''
String username = svcDef.paramsMap.username
String password = svcDef.paramsMap.password
// execute POST request and return a HttpResponse object
HttpResponse response = new PostRequest('https://service.mycorp.com/secure/rest/accounts/')
.setMessage(message)
.setBasicAuth(username, password)
.execute()
// check HttpResponse status code
if (!response.isStatusOK()) {
throw new RuntimeException(response.statusLine)
}
// get Path object from the response
Path path = response.getPathContent()
... -
Class Summary Class Description DeleteRequest Provides a DELETE Request class for performing simple HTTP request operations.GetRequest Provides a GET Request class for performing simple HTTP request operations.HttpRequest Provides an abstract HttpRequest class enabling simpler use of the Apache HTTP Components library.HttpRequest.FileParam Provides a multi-part FileParam.HttpRequest.Param Provides a multi-part Param.HttpResponse Provides a HttpResponse value object class.PatchRequest Provides a PATCH Request class for performing simple HTTP request operations.PostRequest Provides a POST Request class for performing simple HTTP request operations.PutRequest Provides a PUT Request class for performing simple HTTP request operations.RequestBuilder Provides a HTTP Request Builder class.