call REST API using HttpBuilder

Hi,

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..

http://webURL:8111/httpAuth/app/rest/builds/?locator=<buildLocator>

import groovyx.net.http.*

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

println resp.data

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 'http://www.google.com/search?q=groovy' can be passed to Google's REST API like this with RESTClient.

import groovyx.net.http.*

def http = new HTTPBuilder('http://www.google.com')

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.