Hi Szczepan,
i hope i can give you some anchor points with the following hints:
* Planning (Exactly the same procedure as for all other REST-Servers, if you did write one already skip this ;) )
* For a Foxx App you have to consider the following points:
* Which information demand has my web page (e.g. you have a list of users and you want some server-side filtering)
* How to transform this demand into Rest routes (you may know this already if you have created Rails server)
* especially consider the requirements of your frontend framework here, most of them automatically create requests e.g. a Collection in Backbone.js can be given a root url (e.g. "/users" and the framework will then create following requests:
* GET /users -> Fetch the entire list
* POST /users -> Store a new user
* PUT /users/userid -> Update a user
* DELETE /users/userid -> Delete a user
* try to be conform to these frameworks, makes your life easier at the end
* Take into account if you want your app to access global collections (some existing data-source or a shared data-source) or if the data should be local to the App only.
* This point changes the way you have to create a repository in Foxx, it is a minor change but may cause confusion later on.
* Testing
* There is no dedicated test framework for Foxx (yet)
* As you are a Ruby programmer i would suggest to test the REST API with help of HTTParty (or other useful Ruby libraries you have more experience there than i have ;) )
* For these tests:
* define a test database with all necessary test datasets.
* Use arangodump to persist it somewhere.
* Execute your test the following way:
* Start an arranged pointing to an empty data directory
* execute arangoimp to import the test data created above
* execute your tests
* shutdown arangod and remove the data directory
* Alternatively you could use javascript test frameworks (like jasmine or jsunity) and create mocks for server communication (so you catch the outgoing request and return a specified test value)
* This gives the benefit that you do not have to start arangod and you can unit-test your app only.
* "Drawback", you have to learn some javascript ;)
* Debugging
* if you start arangod with —log.file + the logging information will be printed to the screen.
* For debugging you will then get the stack trace (if something breaks you will get two errors, the first error is important for you as it tells you where in the foxx app the crash occurs, the second error is internal as arangodb could not process the broken result from above)
* If you just want to play around with server-side commands (independent of what Foxx adds, like the repositories or models) you can start arangod —console
* This will start an emergency console for arangodb which has exactly the same context as your foxx app has, so what ever is available here will also be available in foxx.
* Then you can just play around with some commands and fine-tune your result and copy the created lines to foxx (recommended for very short sequences only, for a larger sequence look below)
* Furthermore you can just print out any variable in the log.file (or stdout with log.file +) by using require("console“).log(…) this will help to drill down false values that do not cause a crash.
But let me add some additional points that you might find useful:
* Development Mode
* arangod can be started with " --javascript.dev-app-path /some/path " expecting a folder with the subfolder database/_system/<yourfoxxapp>. Then your App will be automatically available at localhost:8529/dev/yourfoxxapp and will automatically be reloaded each request.
* Using this you can immediately see changes in your code applied without the need to uninstall/install the app again and again.
* Production Mode
* In production mode (which you will get when using foxx-manager install) the app will only be loaded once and than cached, so changes in the source code will not be considered until reinstalling the app.
* This gives you a large performance benefit compared to development mode
if you need some further advice feel free to contact me
best
Michael