Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

Hotcode 2013: Javascript in a database (Part 2)

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Chargement dans…3
×

Consultez-les par la suite

1 sur 43 Publicité

Plus De Contenu Connexe

Diaporamas pour vous (20)

Les utilisateurs ont également aimé (20)

Publicité

Similaire à Hotcode 2013: Javascript in a database (Part 2) (20)

Plus par ArangoDB Database (20)

Publicité

Plus récents (20)

Hotcode 2013: Javascript in a database (Part 2)

  1. 1. RWTH Aachen, Computer Science Student on branch master triAGENS GmbH, Developer moonglum moonbeamlabs by Lucas Dohmen Creating APIs for Single Page Web Applications ArangoDB Foxx Samstag, 1. Juni 13
  2. 2. Single Page Web Applications Samstag, 1. Juni 13
  3. 3. The Idea • What if we could talk to the database directly? • It would only need an API • What if we could define this API in JavaScript? Samstag, 1. Juni 13
  4. 4. Single Page Web Applications Samstag, 1. Juni 13
  5. 5. Single Page Web Applications This doesn‘t mean its a Rails/… Killer Samstag, 1. Juni 13
  6. 6. What is ? • Free and Open Source… • … Document and Graph Store… • … with embedded JavaScript… • … and an amazing query language Samstag, 1. Juni 13
  7. 7. Samstag, 1. Juni 13
  8. 8. / (~( ) ) /_/ ( _-----_(@ @) ( / /|/--| V " " " " Samstag, 1. Juni 13
  9. 9. • An easy way to define REST APIs on top of ArangoDB • Tools for developing your single page web application Samstag, 1. Juni 13
  10. 10. Why another solution? • ArangoDB Foxx is streamlined for API creation – not a Jack of all trades • It is designed for front end developers: Use JavaScript, you already know that (without running into callback hell *cough* Node.js) Samstag, 1. Juni 13
  11. 11. Foxx.Application Samstag, 1. Juni 13
  12. 12. Samstag, 1. Juni 13
  13. 13. FoxxApplication = require("org/arangodb/foxx").Application; Samstag, 1. Juni 13
  14. 14. FoxxApplication = require("org/arangodb/foxx").Application; Samstag, 1. Juni 13
  15. 15. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); Samstag, 1. Juni 13
  16. 16. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); Samstag, 1. Juni 13
  17. 17. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { }); Samstag, 1. Juni 13
  18. 18. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { }); Samstag, 1. Juni 13
  19. 19. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { }); res.set("Content-Type", "text/plain"); Samstag, 1. Juni 13
  20. 20. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { }); res.set("Content-Type", "text/plain"); Samstag, 1. Juni 13
  21. 21. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { }); res.set("Content-Type", "text/plain"); res.body = "Worked!"; Samstag, 1. Juni 13
  22. 22. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { res.set("Content-Type", "text/plain"); }); res.body = "Worked!"; Samstag, 1. Juni 13
  23. 23. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { res.set("Content-Type", "text/plain"); }); app.start(applicationContext); res.body = "Worked!"; Samstag, 1. Juni 13
  24. 24. Parameterize the routes • You may want a route like `users/:id`… • …and then access the value of `id` easily Samstag, 1. Juni 13
  25. 25. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users", function(req, res) { res.set("Content-Type", "text/plain"); }); app.start(applicationContext); res.body = "Worked!"; Samstag, 1. Juni 13
  26. 26. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users ", function(req, res) { res.set("Content-Type", "text/plain"); }); app.start(applicationContext); res.body = "Worked!"; Samstag, 1. Juni 13
  27. 27. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); }); app.start(applicationContext); res.body = "Worked!"; Samstag, 1. Juni 13
  28. 28. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); }); app.start(applicationContext); res.body = "Worked!"; Samstag, 1. Juni 13
  29. 29. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); res.body = "Your User: " + req.params("id"); }); app.start(applicationContext); Samstag, 1. Juni 13
  30. 30. • In your Foxx.Application you describe your routes • But your application can consist of multiple Foxx.Applications • … and you also want to deliver assets and files Manifest.json Samstag, 1. Juni 13
  31. 31. { "name": "my_website", "version": "1.2.1", "description": "My Website with a blog and a shop", "thumbnail": "images/website-logo.png", "apps": { "/blog": "apps/blog.js", "/shop": "apps/shop.js" }, "assets": { "application.js": { "files": [ "vendor/jquery.js", "assets/javascripts/*" ] } } } Samstag, 1. Juni 13
  32. 32. { "name": "my_website", "version": "1.2.1", "description": "My Website with a blog and a shop", "thumbnail": "images/website-logo.png", "apps": { "/blog": "apps/blog.js", "/shop": "apps/shop.js" }, "assets": { "application.js": { "files": [ "vendor/jquery.js", "assets/javascripts/*" ] } } } Samstag, 1. Juni 13
  33. 33. { "name": "my_website", "version": "1.2.1", "description": "My Website with a blog and a shop", "thumbnail": "images/website-logo.png", "apps": { "/blog": "apps/blog.js", "/shop": "apps/shop.js" }, "assets": { "application.js": { "files": [ "vendor/jquery.js", "assets/javascripts/*" ] } } } Samstag, 1. Juni 13
  34. 34. More • Define a setup and teardown function to create and delete collections • Define lib to set a base path for your require statements • Define files to deliver binary data unaltered Samstag, 1. Juni 13
  35. 35. Documentation as a first class citizen Samstag, 1. Juni 13
  36. 36. Annotate your Routes • For Documentation • But will later also be used for validation etc. Samstag, 1. Juni 13
  37. 37. FoxxApplication = require("org/arangodb/foxx").Application; app = new FoxxApplication(); app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); res.body = "Your Wiese: " + req.params("id"); }); app.start(applicationContext); Samstag, 1. Juni 13
  38. 38. app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); res.body = "Your Wiese: " + req.params("id"); }); Samstag, 1. Juni 13
  39. 39. app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); res.body = "Your User: " + req.params("id"); }); Samstag, 1. Juni 13
  40. 40. app.get("/users/:id", function(req, res) { res.set("Content-Type", "text/plain"); res.body = "Your User: " + req.params("id"); }); }).pathParam("id", { description: "ID of the User", dataType: "int" Samstag, 1. Juni 13
  41. 41. Automatically generate Swagger Docs Samstag, 1. Juni 13
  42. 42. If you want to learn about • … how we use the Repository Pattern • … how you can structure your Foxx App Samstag, 1. Juni 13
  43. 43. Join us at our workshop tomorrow 11:00 DB Stage Samstag, 1. Juni 13

×