shred.js | |
---|---|
Shred is an HTTP client library intended to simplify the use of Node's built-in HTTP library. In particular, we wanted to make it easier to interact with HTTP-based APIs. See the examples for more details. | var _ = require("underscore") |
Ax is a nice logging library we wrote. You can use any logger, providing it
has | , Ax = require("ax")
; |
Shred takes some options, including a logger and request defaults. | var Shred = function(options) {
options = (options||{});
this.defaults = options.defaults||{};
this.log = options.logger||(new Ax({ level: "info" }));
}; |
Most of the real work is done in the request and reponse classes. |
Shred.Request = require("./shred/request");
Shred.Response = require("./shred/response"); |
The | Shred.prototype = {
request: function(options) {
options.logger = this.log;
return new Shred.Request(_.defaults(options,this.defaults));
}
}; |
Define a bunch of convenience methods so that you don't have to include
a | "get put post delete".split(" ").forEach(function(method) {
Shred.prototype[method] = function(options) {
options.method = method;
return this.request(options);
};
});
module.exports = Shred;
|