Your SlideShare is downloading. ×
Rapid API Development ArangoDB Foxx
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Rapid API Development ArangoDB Foxx

430
views

Published on

Published in: Software, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
430
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. by Michael Hackstein @mchacki Rapid API Development ArangoDB Foxx
  • 2. Michael Hackstein @mchacki • Member of ArangoDB Core Team • web front-end • graph features • Organizer of cologne.js • Master’s Degree
 (spec. Databases and
 Information Systems)
  • 3. Classical Web Applications Application Logic
  • 4. Single Page Web Applications Application Logic
  • 5. 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?
  • 6. Single Page Web Applications This doesn‘t mean its a Rails/… Killer
  • 7. Client Server DB
  • 8. Client Server (optional) DB with Foxx
  • 9. What is ? • a multi-model database (document store & graph database) • is open source and free (Apache 2 license) • offers convenient queries (via HTTP/REST and AQL) • offers high performance and is memory efficient • uses JavaScript throughout (V8 built into server) • doubles as a web and application server (Foxx) • offers many drivers for a wide range of languages • is easy to use with web frontend and good documentation • enjoys good professional as well as community support • and recently added sharding in Version 2.0.
  • 10. / (~( ) ) /_/ ( _-----_(@ @) ( / /|/--| V " " " "
  • 11. • … a feature of ArangoDB since 1.4 • … an easy way to define REST APIs on top of ArangoDB • … a toolset for developing your single page web application • … not requiring any special code on the client side – use it with Angular, Backbone, Ember,… Foxx is…
  • 12. Why another solution? • ArangoDB Foxx is streamlined for API creation – not a Jack of all trades • There‘s no communication overhead between (serverside) application and database • It is designed for front end developers: Use JavaScript, you already know that
  • 13. Foxx.Controller
  • 14. Foxx = require("org/arangodb/foxx");
  • 15. Foxx = require("org/arangodb/foxx"); controller = new Foxx.Controller(appContext);
  • 16. Foxx = require("org/arangodb/foxx"); controller = new Foxx.Controller(appContext); controller.get("/users", function(req, res) { });
  • 17. Foxx = require("org/arangodb/foxx"); controller = new Foxx.Controller(appContext); controller.get("/users", function(req, res) { res.json({ hello: "world" }); });
  • 18. Parameterize the routes • You may want a route like `users/:name`… • …and then access the value of `name` easily
  • 19. Foxx = require("org/arangodb/foxx"); ! controller = new Foxx.Controller(appContext); ! controller.get("/users", function(req, res) { res.json({ hello: "world" }); });
  • 20. Foxx = require("org/arangodb/foxx"); ! controller = new Foxx.Controller(appContext); ! controller.get("/users ", function(req, res) { res.json({ hello: "world" }); }); /:name
  • 21. Foxx = require("org/arangodb/foxx"); ! controller = new Foxx.Controller(appContext); ! controller.get("/users ", function(req, res) { res.json({ hello: "world" }); }); req.params("name"); /:name
  • 22. • In your Foxx.Controller you describe your routes • But your application can consist of multiple Foxx.Controllers • … and you also want to deliver assets and files Manifest.json
  • 23. { "name": "my_website", "version": "1.2.1", "description": "My Website with a blog and a shop", "thumbnail": "images/website-logo.png", ! "controllers": { "/blog": "apps/blog.js", "/shop": "apps/shop.js" }, ! "assets": { "application.js": { "files": [ "vendor/jquery.js", "assets/javascripts/*" ] } } }
  • 24. { "name": "my_website", "version": "1.2.1", "description": "My Website with a blog and a shop", "thumbnail": "images/website-logo.png", ! "controllers": { "/blog": "apps/blog.js", "/shop": "apps/shop.js" }, ! "assets": { "application.js": { "files": [ "vendor/jquery.js", "assets/javascripts/*" ] } } }
  • 25. { "name": "my_website", "version": "1.2.1", "description": "My Website with a blog and a shop", "thumbnail": "images/website-logo.png", ! "controllers": { "/blog": "apps/blog.js", "/shop": "apps/shop.js" }, ! "assets": { "application.js": { "files": [ "vendor/jquery.js", "assets/javascripts/*" ] } } }
  • 26. 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
  • 27. Documentation as a first class citizen
  • 28. Annotate your Routes • For Documentation • But it is also used for validation
  • 29. controller.get("/users/:name", function(req, res) { res.json({ hello: req.params("name"); }); });
  • 30. controller.get("/users/:name", function(req, res) { res.json({ hello: req.params("name"); }); }).pathParam("name", { description: "Name of the User", dataType: "string" }); ;
  • 31. controller.get("/users/:name", function(req, res) { res.json({ hello: req.params("name"); }); }).pathParam("name", { description: "Name of the User", dataType: "string" }); /** What's my name? * * This route knows it. */
  • 32. Automatically generate Swagger Docs
  • 33. Foxx.Repository and Foxx.Model
  • 34. Domain Models Persistence Foxx.Model Foxx.Repository
  • 35. Foxx.Model Foxx.Repository • Representation of the data • Convenience Methods • Validation • Save and Retrieve Data • Simple Queries • Define your own queries
  • 36. Why this separation? • It doesn‘t violate the SRP like ActiveRecord • In a lot of cases you can use the standard Repository or Model and don‘t need your own • It‘s great for testing • You can mock the collection and the model prototype to test your Repository • You don‘t need to mock anything to test your model
  • 37. Foxx.Model • The constructor takes a hash of attributes • Access the attributes with get, set and has • The forDB will be used to write the data into the database • Use forClient to prepare the data for delivery
  • 38. Foxx.Repository • The constructor takes an arangodb- collection and the prototype of the model • save for example expects an instance of the model • firstExample finds a suitable dataset and returns it as an instance of the model • Other methods: remove, replace, update…
  • 39. You need more? • Use Foxx.Repository.extend and Foxx.Model.extend to inherit from the prototype • Add your own methods • Your extensions live in separate files
  • 40. Foxx = require("org/arangodb/foxx");! ! MyRepository = Foxx.Repository.extend({ });! ! exports.Repository = MyRepository;
  • 41. byName: function (name) {! return this.byExample({! name: name! });! } Foxx = require("org/arangodb/foxx");! ! MyRepository = Foxx.Repository.extend({ });! ! exports.Repository = MyRepository;
  • 42. Thanks • Please try ArangoDB Foxx • www.arangodb.org • We to get feedback
  • 43. Contact • I am mchacki everywhere: • mchacki@arangodb.org • @mchacki on Twitter • mchacki on Github
  • 44. Thanks • First Slide version by Lucas Dohmen • Database icon designed by Romeo Barreto from The Noun Project • Logos from Node.js, Ruby on Rails, Django, AngularJS, Backbone, Ember and Symfony from the respective projects • All other icons are from Font Awesome