Gradle Script To call a REST Web service without any 3rd party plugins, any pointers?
Can't you just do
new URL( 'http://username:[email protected]:8983/solr/select?q=*&wt=json' ).text
this is working guys
import java.io.*
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.EncoderRegistry
import static groovyx.net.http.Method.*
import static groovyx.net.http.ContentType.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2'
}
}
task hello {
def http = new groovyx.net.http.HTTPBuilder("http://local.com:8983/solr/update/json")
http.request(POST, JSON ) { req ->
req.body{
}
response.success = { resp, reader ->
println "$resp.statusLine Respond rec"
}
}
}
The easiest way to call REST from groovy without external libraries is executing CURL. Here's an example of calling Artifactory, getting JSON back and parsing it:
import groovy.json.JsonSlurper
task hello {
def p = ['curl', '-u', '"admin:password"', "\"http://localhost:8081/api/storage/libs-release-local?list&deep=1\""].execute()
def json = new JsonSlurper().parseText(p.text)
}