docs: function(res) {
      res.setEncoding('utf8');
      var data = "";
      res.on('data', function(chunk) {
        data+=chunk;
      });
  
      res.on('end', function() {
        // Get HTTP Statuscode and act according to situation
        var code = res.statusCode;
        try { // try to parse JSON
          var answer = JSON.parse(data);
        } catch (e) {
          var err = {};
          err.http_code = 500;
          err.message = "No valid JSON received: "+data;
          callback(err, null);
          return;
        }
        if(code >= 200 && code <= 206) { // request was successful
          callback(null, answer);
        } else if (code >= 300 && code <= 307) { // server send redirect
          // we do not follow anything the server wants us to follow right now, since this should never be the case.
          // instead let's raise an error.
          var err = new Object();
          err.http_code = 500;
          err.message = "Redirects not supported by pastyclient-node"
          callback(err, null);
        } else if (code >= 400 && code <= 418) { // client error
          if(typeof(answer.error) == "object") {
            var err = answer.error;
          } else if(answer.code != undefined && answer.message != undefined) { // New RestError, temporary support both 
            var err = answer;
            err.http_code = code;
          } else {
            var err = new Object();
            err.http_code = code;
            err.message = "Resource not found";
          }
          callback(err, null);
        } else if (code >= 500 && code <= 505) { // server error
          if(typeof(answer.error) == "object") {
            var err = answer.error;
          } else {
            var err = new Object();
            err.http_code = code;
            err.message = "Internal Server Error";
          }
          callback(err, null);
        } else {
          // Not existant HTTP code. Raise error.
          var err = new Object();
          err.http_code = 500;
          err.message = "HTTP Status Code "+code+" is not supported by pastyclient-node"
          callback(err, null);
        }
      });
    }