groovy

RESTClient

Introduction#

Groovy’s HTTP Client usage, examples and pitfalls.

GET Request

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

import groovyx.net.http.RESTClient

try {
    def restClient = new RESTClient("https://weathers.co")
    def response = restClient.get(path: '/api.php', query: ['city': 'Prague'])
    println "Status     : ${response.status}"
    println "Body       : ${response.data.text}"
} catch (Exception e) {
    println "Error      : ${e.statusCode}"
    println "Message    : ${e.response.data}"
}

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow