Please build a module using the request package that has
two methods, getURL and postURL. You can think of it as a simple wrapper around request
.
moduleName.getURL(url, callback); // url: path to GET url,
// callback: function of type (err, statusCode, body)
moduleName.postURL(url, jsonData, callback); // url path to POST,
// jsonData: json obj to post to server,
// callback: same as above
- Mocha, write tests for this module
- Use the debug module for your debug message. Set debug type to worker. Use debug messages in your module!
- Method getUrl - take a URL, ensure it is not null or empty string, then perform GET request.
Return error if request returns error object or if
statusCode !== 200
. Otherwise return null for the error and pass the body back to the callback. - Method postURL - take URL, ensure it is not null or empty string, take postData, ensure it is
not null or undefined, then post the JSON data to the server. Return error if request returns
error or if
statusCode !== 200
. Otherwise return null for the error and pass the body back to the callback.
- Successful getURL using github.com
- Successful postURL using posttestserver.com (this will allow you to see your POST data publically follow the URL in the return body.) Please post something silly like your name and current time for testing.
- Pass in null to getURL and make sure it gets error back.
Get it on github, not on npm yet :(
var nodetask = require('nodetask');
nodetask.getUrl('http://www.url.com', function(err, statusCode, body) {
console.log(err, statusCode, body);
});
nodetask.postUrl('http://www.url.com', {key1: 'value1', key2: 'value2'}, function(err, statusCode, body) {
console.log(err, statusCode, body);
});
npm test
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
- 0.1.0 Initial release