Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Foxx Talk at SFJS

Foxx Talk at SFJS

I gave this talk at the [San Francisco JavaScript Meetup](http://www.meetup.com/jsmeetup/events/176447712).

Lucas Dohmen

May 14, 2014
Tweet

More Decks by Lucas Dohmen

Other Decks in Programming

Transcript

  1. RWTH Aachen, Computer Science Student on branch master triAGENS GmbH,

    Developer moonglum moonbeamlabs by Lucas Dohmen Create APIs on your database ArangoDB Foxx
  2. 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?
  3. Who is that guy? • ArangoDB Core Team • ArangoDB

    Foxx & Ruby Adapter • From Germany /\ (~( ) ) /\_/\ ( _-----_(@ @) ( \ / /|/--\|\ V " " " "
  4. What is ? • Free and Open Source… • …

    Document and Graph Store… • … with embedded JavaScript… • … and an amazing query language
  5. • …a feature of ArangoDB • …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 Backbone, Ember, Angular… Foxx is…
  6. 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
  7. Parameterize the routes • You may want a route like

    `users/:name`… • …and then access the value of `name` easily
  8. Foxx = require("org/arangodb/foxx"); ! controller = new Foxx.Controller(appContext); ! controller.get("/users

    ", function(req, res) { res.json({ hello: "world" }); }); req.params("name"); /:name
  9. • In your Foxx.Controller you describe your routes • In

    the Manifest file you describe where to mount each controller • Plus meta information + asset management Manifest.json
  10. 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. */
  11. Foxx.Model Foxx.Repository • Representation of the data • Convenience Methods

    • Validation • Save and Retrieve Data • Simple Queries • Define your own queries
  12. 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
  13. Foxx.Repository • The constructor takes a 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…
  14. 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
  15. byName: function (name) {! return this.byExample({! name: name! });! }

    Foxx = require("org/arangodb/foxx");! ! MyRepository = Foxx.Repository.extend({ });! ! exports.Repository = MyRepository;
  16. 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
  17. Foxx Apps Repo • Look at demo applications • Install

    components from a central repository • Share your ideas
  18. The Future • Hypermedia support with a declarative approach •

    Including JSON API • Helping you with your ROA • Built-in support for Background Workers
  19. Thanks • Please try ArangoDB & ArangoDB Foxx • We

    to get feedback • [email protected] • @moonbeamlabs on Twitter
  20. Thanks • Database icon designed by Romeo Barreto from The

    Noun Project • Browser icon designed by Fernando Vasconcelos from The Noun Project • Logos from Node.js, Ruby on Rails, Django and Symfony from the respective projects • All other icons are from Font Awesome