Class GetRequest


  • public class GetRequest
    extends HttpRequest

    Provides a GET Request class for performing simple HTTP request operations. This class provides an easier and safer interface for the Apache HTTP Components library.

    The default connection timeout is 10 seconds and socket read timeout is 60 seconds. Socket connections will also apply any JVM proxy settings automatically.

    By default the maximum response read size is 16 MB. If the response is larger than this an IOException will be thrown. To increase the maximum read limit use the HttpRequest.setReadLimit(int) method.

    In RESTful services the GET method is used to retrieve resources specified by the URI.

    Examples

    The example below performs REST request and returns a JSON 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 Path object from the response
         Path path = response.getPathContent()
         ...
    
     } else if (response.isStatusNotFound()) {
         // object not found
         ...
    
     } else {
         throw new RuntimeException(response.statusLine)
     } 
    Since:
    5.0.0
    See Also:
    DeleteRequest, PatchRequest, PutRequest, PostRequest
    • Constructor Detail

      • GetRequest

        public GetRequest​(String uri)
        Create a GET HTTP request object with the given URI.
        Parameters:
        uri - the request URI (required)