... but I get no result
You get the result, an empty Buffer , but it does not want you to like it, perhaps.
The point is that you are using the read method incorrectly, passing it in a callback to the get method. The get , post , put and delete methods already call read internaly and return a readable Buffer for you in the callback. Take a look at get doc :
get (uri, [options], callback)
Convenient method for GET operations.
- uri - URI of the requested resource.
- options is an additional configuration object containing settings for query and read operations.
- callback - callback function using the signature function (err, response, payload), where:
- err is any error that may have occurred during request processing.
- response is an HTTP Incoming Message object, which is also a readable stream.
- payload - payload in the form of a buffer or (optionally) parsed JavaScript object (JSON).
Thus, using the get method is quite simple (using your own example):
var callback = function(err, response, payload){ console.log(payload.toString());
source share