Superagent wrapper with base URL support
November 11, 2014 ยท View on GitHub
var request = require("superagent");
/**
- Superagent wrapper for easily making AJAX requests. Provides a layer of
- convenience by adding a base URL to each request. The base URL is derived
- from the
API_URLenvironment variable. / module.exports = { /*- DELETE relative
pathwith optional callbackfn(res). - @method del
- @param {String} path
- @param {Function} fn
- @return {Request}
- @public */ del: function(path, fn) { return ( request .del(process.env.API_URL + path, fn) ); },
- DELETE relative
/**
- GET relative
pathwith optionaldataand callbackfn(res). - @method get
- @param {String} path
- @param {Mixed} data
- @param {Function} fn
- @return {Request}
- @public */ get: function(path, data, fn) { return ( request .get(process.env.API_URL + path, data, fn) ); },
/**
- PATCH relative
pathwith optionaldataand callbackfn(res). - @method patch
- @param {String} path
- @param {Mixed} data
- @param {Function} fn
- @return {Request}
- @public */ patch: function(path, data, fn) { return ( request .patch(process.env.API_URL + path, data, fn) ); },
/**
- POST relative
pathwith optionaldataand callbackfn(res). - @method post
- @param {String} path
- @param {Mixed} data
- @param {Function} fn
- @return {Request}
- @public */ post: function(path, data, fn) { return ( request .post(process.env.API_URL + path, data, fn) ); },
/**
- PUT relative
pathwith optionaldataand callbackfn(res). - @method put
- @param {String} path
- @param {Mixed} data
- @param {Function} fn
- @return {Request}
- @public */ put: function(path, data, fn) { return ( request .put(process.env.API_URL + path, data, fn) ); } }