Zen Mojo - REST vs native transport?
I am going to start playing with Zen Mojo (again) and as I understand it there are two ways to manage moving data to/from your Zen Mojo page:
- interacting with REST services
- using Mojo's built-in transport
I would like to understand the pros and cons of each approach. Which is recommended in different situations and why? I would like to create a sample application that will hopefully be reusable and helpful to others and I would like to understand which approach to pick for my app.
In the experience of the Community, how do the above two approach compare in terms of:
- Ease of use
- Rapid application development (which is faster for getting a workable app up and running?)
- Maintenance time / costs
- Flexibility
I would appreciate hearing people's experiences and recommendations.
Thanks!
Ben
Wouldn't REST allow you to test/debug things system-agnostic? Since there are countless REST clients you could use.
I prefer REST.
The built-in transportation is good way for ZEN but the fact that the most plugins can't handle it well is a good reason to use REST. Some plugins just want an URL to do a simple jQuery-AJAX-Call and parsing that into a callback function. I some cases you can submit a function serving the data instead of an URL but working that around that is a bit harsh and not really comfortable in my opinion (Typeahead for example).
Let's assume that you code a ZEN-App working with Cordova and in the Browser as well. The data comes from the built-in feature of ZEN-Mojo. Everything works fine.
Now a new iOS or Android-Update is distributed that have new security guidelines and Cordova dies out of it (maybe some stuff in the webview are not allowed anymore but is needed). That's why I keep my data-transportation as flexible as possible. Always thinking of "This 3rd party tool is maybe not supported anymore in the future. What are my alternatives?". In this case a native app without ZEN.
You can still use the built-in feature by calling the methods that the REST calls. You are in the CSP-Enviroment in both cases.
Thanks Jochen - I appreciate your thoughts on this!
Whether you should be using the default transport layer of Zen and Zen Mojo or built your own REST interface depends on a couple of things:
If you have to serve multiple front-ends, e.g. a native mobile app, a web app and some data to a reporting layer then a REST interface makes you more flexible to actually meet the data needs of each of them without duplicating too much code.
If you just want to get your Zen/Zen Mojo application working without too much extra learning, the standard transport way is just fine.
In general REST interfaces are just a clean way to build your communication layer. If you make your REST calls in the Zen Mojo onGetContent method you will still get the benefits of client-side caching within Zen Mojo. The only real difference is that your data retrieval code now lives in a separate class (a subclass of %CSP.REST) instead of a Zen Mojo template.
REST interfaces are indeed easier to test and debug as they can be tested by tools. The Zen / Zen Mojo client/server communication requires some knowledge if you really want to know what is going on.
HTH,
Stefan