Class PutRequest

java.lang.Object
com.avoka.component.http.HttpRequest
com.avoka.component.http.PutRequest

public class PutRequest extends HttpRequest
Provides a PUT 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 PUT method is used to update resources.

Examples

The example below performs PUT request and converts the response into a JSON document

 import com.avoka.component.http.PutRequest

 def message = '{ "cutomerId":82881, "name":"John Doe", "email":"[email protected]", "age":42 }'

 def username = serviceParameters.username
 def password = serviceParameters.password

 // execute PUT request and return a HttpResponse object
 def response = new PutRequest('https://service.mycorp.com/secure/rest/accounts/')
       .setMessage(message)
       .setBasicAuth(username, password)
       .execute()

 // check HttpResponse status code
 if (response.status == 200) {
     // get JSON object from the response
     def json = response.getJsonContent() {
     ...

 } else if  (response.status == 404) {
     // Not found
     ...

 } else {
     throw new RuntimeException(response.statusLine)
 } 
Since:
4.2.0
See Also:
  • Constructor Details

    • PutRequest

      public PutRequest(String url)
      Create a PUT HTTP request object with the given URL.
      Parameters:
      url - the request URL (required)