I'm attempting to switch to HttpBuilder-NG but having some difficulty with it. I can't seem to find any concrete examples of working with response headers or even the response status code. It was beyond simple with the old httpbuilder - RESTClient to be specific. Also, I use it for testing. Here's one example I need translated to HttpBuilder-NG
def r = client.get(path: '/ws/v1/ping')
assert r.status == 200
what does that look like in HttpBuilder-NG?
Your comment put me on the right track. Thank you! I am hoping to avoid rewriting thousands of lines of test code by making a wrapper class around HttpBuilder-NG so it will return objects similar to the old HttpBuilder/RESTClient. Also, something similar could help people that are trying to get away from wslite. Here's what I've come up with so far, in case it is helpful for other people:
def client = HttpBuilder.configure {
request.uri = 'https://myServer.server.org'
request.auth.basic 'user1', 'fakePass1'
ignoreSslIssues execution
}
//use the client to make hit the ping endpoint
def r = client.get {
request.uri.path = path+'ping'
response.success {FromServer fs, body ->
[status: fs.statusCode,
headers: fs.headers,
data: body
]
}
}
assert r.status == 200
assert r.headers.size() > 0
assert r.data[0] == 'pong'