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()
 ...