rest-gen: Add Node.js support

This commit changes the base JavaScript code to work both as a Node.js
module and as a browser script. It should also work as an AMD module.
When running in Node.js, the API will use the `request` package to make
the HTTP requests, instead of jQuery's AJAX functionality.