     host: mqConfig.host
     port: mqConfig.apiPort
     auth: mqConfig.login + ':' + mqConfig.password
-    path: '/api/' + method
+    path: "/api/#{method}"
     method: 'GET'
 
   req = http.request options, (res) ->
     res.setEncoding 'utf8'
-    res.on 'data', (chunk) ->
-      callback null, chunk
+    res.body = ''
+    res.on 'data', (chunk) -> res.body+=chunk
+    res.on "end", -> callback null, res.body
 
-  req.on 'error', (e) ->
-    callback e, null
-
+  req.on 'error', (error) ->
+    callback error, null
+  
   req.end()
 
 apiSet = (method, args, callback) ->


  req = http.request options, (res) ->
    res.setEncoding 'utf8'

    # rabbit api sends a 204 for succesfull put and delete requests
    if res.statusCode is 204
      callback null, JSON.stringify {ok: "request successful"}
    else
      res.on "data", (chunk) ->
        body = JSON.parse chunk
        if body.error?
          callback body, null

  req.on 'error', (e) ->
    console.log e
    callback e, null

  req.write JSON.stringify args
  req.end()


  req = http.request options, (res) ->
    res.setEncoding 'utf8'
    res.body = ''
    res.on "data", (chunk)-> res.body += chunk
    res.on "end", ->
      # rabbit api sends a 204 for succesfull put and delete requests
      if res.statusCode is 204
        callback null, JSON.stringify {ok: "request successful"}
      else
        try
          body = JSON.parse chunk
        catch error
          console.log error
          body = {error: "response should be json."}
        
        if body.error?
          callback body, null

  req.on 'error', (error) ->
    console.log error
    callback error, null

  req.write JSON.stringify args
  req.end()
