ArangoDB’s Actions
It is recommended to use Foxx instead.
Introduction to User Actions
In some ways the communication layer of the ArangoDB server behaves like a Webserver. Unlike a Web server, it normally responds to HTTP requests by deliveringJSON objects. Remember, documents in the database are just JSON objects. So,most of the time the HTTP response will contain a JSON document from thedatabase as body. You can extract the documents stored in the database usingHTTP GET. You can store documents using HTTP POST.
However, there is something more. You can write small snippets - so calledactions - to extend the database. The idea of actions is that sometimes it isbetter to store parts of the business logic within ArangoDB.
The simplest example is the age of a person. Assume you store information aboutpeople in your database. It is an anti-pattern to store the age, because itchanges every now and then. Therefore, you normally store the birthday and letthe client decide what to do with it. However, if you have many differentclients, it might be easier to enrich the person document with the age usingactions once on the server side.
Or, for instance, if you want to apply some statistics to large data-sets andyou cannot easily express this as query. You can define a action instead oftransferring the whole data to the client and do the computation on the client.
Actions are also useful if you want to restrict and filter data according tosome complex permission system.
The ArangoDB server can deliver all kinds of information, JSON being only onepossible format. You can also generate HTML or images. However, a Web server isnormally better suited for the task as it also implements various cachingstrategies, language selection, compression and so on. Having said that, thereare still situations where it might be suitable to use the ArangoDB to deliverHTML pages - static or dynamic. A simple example is the built-in administrationinterface. You can access it using any modern browser and there is no need for aseparate Apache or IIS.
In general you will use Foxx to easily extend the database withbusiness logic. Foxx provides an simple to use interface to actions.
The following sections will explain the low-level actions within ArangoDB onwhich Foxx is built and show how to define them. The examples start withdelivering static HTML pages - even if this is not the primary use-case foractions. The later sections will then show you how to code some pieces of yourbusiness logic and return JSON objects.
The interface is loosely modeled after the JavaScript classes for HTTP requestand responses found in node.js and the middleware/routing aspects of connect.jsand express.js.
Note that unlike node.js, ArangoDB is multi-threaded and there is no easy way toshare state between queries inside the JavaScript engine. If such stateinformation is required, you need to use the database itself.