In this snippet, a closure is defined with request information. You can set various pieces of the request or response such as headers, content type, paths and how to handle response behavior. We will specify the request method as a GET, content type as text, two closures to handle the response and location of groovy examples. The first closure to handle the response is to handle if it is a success and the second if the response fails. When the status code is 200 we will output response, content type and response contents text to the console. If it fails a message will appear with not found.
Convenience GET method
This snippet will show how to use the convenience method to perform an HTTP GET. Similar to above we will make a request to leveluplunch groovy examples while specifying the path and content type. Only major difference is we will output each header name/value and remove the response closure as the http.get method will only handle a successful response.