call REST API using HttpBuilder


I'm trying to make calls to TC's REST API with a well-known http client called RESTClient (HttpBuilder is another variation of it). Not sure if anybody has tried to do it. I'm having some issue passing the query paramenters. Here's my code to grab the data of a build using following query string and code to pass similar string to TC's REST API..



def webURL = 'http://localhost'
def port = 8090
def userName = 'xxx'
def password = 'xxx'

def restClient = new RESTClient(webURL)
restClient.headers['Authorization'] = 'Basic '+ (userName + ':' + password).bytes.encodeBase64()
def resp = restClient.get(path:'/httpAuth/app/rest/builds', query:[locator:(id:build_id)])

println "Status: " + resp.status
assert resp.status == 200
println "ContentType: "+ resp.contentType


But I have some syntactic error with multiple colons in the query (tried enclosing them in parenthesis as well).

Just to give an idea of how to pass the query part of an URL to RESTClient, here's a simple example

The query '' can be passed to Google's REST API like this with RESTClient.


def http = new HTTPBuilder('')

http.get( path : '/search', query : [q:'Groovy'] ) { resp, reader ->
println "response status: ${resp.statusLine}"
println 'Response data: -----'
System.out << reader

My question is how will I pass these locators when I'm using RESTClient.

Please sign in to leave a comment.