The Drupal community can now proudly claim its own implementation of a Todo app with a RESTful backend!
TodoMVC is a site that helps you select the right JS MVC library. But more then that, it allows you to learn by comparing those libraries, as they all implement the same thing - a simple Todo app.
As it turns out, TodoMVC’s good folks have written the Angular app with both an API backend and a local storage one. If no backend is found, it silently falls back to local storage.
This means all I had to do was to write the RESTful resource. You can take a look at the code needed, to appreciate how very little effort is required to make Drupal a proper RESTful server that Simply Works.
On the client side I did two slight modifications:
- Added the ability to inject the
ENVwith a configurable backend URL (to enable local/production/etc development environments)
- Changed the response the app was expecting after create/update, from
todo.id = resp.data.id;to
todo.id = resp.data.data.id;
(Note that I could have kept the demo app completely unchanged and do this on the server side by writing a custom RESTful formatter that would wrap the result as expected by the app)
Keeping with “The Gizra Way” obsession with best practices, the entire package is published as an installation profile. It even has a Behat test to verify it’s installed properly! Go ahead and try the app.