Last active
March 9, 2016 20:29
-
-
Save ovrmrw/c96d6a6dfc349d08e392 to your computer and use it in GitHub Desktop.
sample: ArangoDB's Foxx controller with using any library you want
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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