Favourite Quote

Every artist was first an amateur. - Ralph Waldo Emerson The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be. - Horace Bushnell

Friday, May 29, 2015

Building a Nested JSON using HTTPBuilder in Groovy

Here is an example of how to pass a JSON that is nested with a HTTPBuilder
private def getWorkingLatitude(String additionalInfo)
              def json = new JsonBuilder()
  json {
   "jobId" additionalInfo
                         "mobilePhone" "0123469521"
                         "homePhone" "01235698470"
  return json;

Here is how you wrap it with HTTPBuilder
HTTP_BUILDER.request(Method.PUT, ContentType.JSON){
   headers.'Authorization' = "Bearer "+ ACCESS_TOKEN_TM
   uri.path =  JOB_URI_PREFIX +USER_ID_TM+"/reject"
   println "uri job is : "+uri.path
   body = json.toString()

No comments:

Post a Comment