Skip to content

Instantly share code, notes, and snippets.

@ovrmrw
Last active March 9, 2016 20:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovrmrw/c96d6a6dfc349d08e392 to your computer and use it in GitHub Desktop.
Save ovrmrw/c96d6a6dfc349d08e392 to your computer and use it in GitHub Desktop.
sample: ArangoDB's Foxx controller with using any library you want
(function() {
"use strict";
var Foxx = require("org/arangodb/foxx"),
controller = new Foxx.Controller(applicationContext),
_ = require("underscore"), // loading underscore.js in C:\Program Files\ArangoDB 2.2.4\share\arangodb\js\node\node_modules
moment = require("moment"); // loading moment.js in C:\Program Files\ArangoDB 2.2.4\share\arangodb\js\node\node_modules
controller.get("/hello/:name", function(req, res) {
res.set("Content-Type", "text/plain");
res.body = "Hello " + req.params("name");
});
// MAIN TOPICS IS FROM HERE
// If your Foxx app is deployed to 'http://localhost:8529/dev/my_app/',
// put the url 'http://localhost:8529/dev/my_app/momentSample' then you'll get a result of the now time as JSON.
controller.get("/momentSample", function(req, res) {
var result = "";
if (_.isObject(moment)) { // enable to use underscore functions.
result = "Result of moment function: " + moment().format("YYYY-MM-DD hh:mm"); // enable to use moment functions.
}
res.json({ result: result });
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment