I don’t vent very often… but I think this deserves a good vent.

HTTPBuilder is a tool that Groovy/Grails can utilize to make API calls and parse/validate the results.  It sounds great, expect the examples and documentation is extremely sparse.

Where I want to vent, is on the topic of Validation.  The documentation on HTTPBuilder doesn’t go too deep into handling real validation of API responses… but it seems that’s the norm.  I had an issue trying to parse some JSON that was formatted from the HTTPBuilder response like so:

[

      {

         “id” : 1

         “name” : “blah”

      }

]

In the past, I could just do a resp.data[0] and get access to the JSON.  Well these days HTTPBuilder or Groovy/Grails is giving me hell.  I got some errors trying to do that so I started looking on line for a solution.

What I discovered was that in the dozens of blogs and tutorials online, developers and users of HTTPBuilder are certifying API responses as valid by simply checking the status.  In other words:

resp.status == 200

That’s a huge mistake.  A working service will respond with 200 OK, but it could be giving you incorrect data.  What I found is that few people are using HTTPBuilder to actually validate the response data!

From a QA perspective that’s insane.  In fact, case in point, I had a rest service I was hitting that was giving a 200OK but it wasn’t returning the right data.

When tests are written to validate API end points they need to have data validation.  You can’t not rely on something as simple as did I get a 200?? That’s the equivalent of a Dr. in the ER simply marking someone healthy because they got a heart beat.

As to my issue, I did get a solution – but it wasn’t easy. I had to weed through dozens of posts about “validation with HTTPBuilder” that really was just checking status codes.  In my case, I found a solution that I’ll post in a different topic.

Leave a Reply

Your email address will not be published. Required fields are marked *