My aim is to build a functioning web application that I can note down my moods on any given day and track them over time to give me a few pretty graphics.
It has taken me quite awhile to pull everything together, and I'm still working on it as we speak but I've got a basic framework that I can build on now.
I decided to go with AngularJS for the client-side code, and the Flask Python library for my API. All data that is displayed to the user is collected by AngularJS through object endpoints that I've created in Flask using Flask-Restless.
Server-sideThe developers of SQLAlchemy (a database-independent DBMS for Python) have a plugin for Flask that allows the user to access database records as individual Pythonic objects which is really neat. Pass these objects into Flask-Restless and you have ready made object endpoints that you can access from /api/Object/:objectid:. This is really fricking neat. I decided to set my app up with just a User and a set of Entries, which would be associated with the User through a one-to-many relationship, which Flask and SQLAlchemy set up rather nicely. A quick note: when you link a DBO with another in a one-to-many relationship, it is unclear how to add new "many" objects using RESTful verbs. The Flask-Restless docs don't really cover this well and I needed to rummage around to find the actual data structure to pass through. Here's an example for adding an entry to the User:
Endpoint URL: /api/User/:userid:**JSON encoded request data:**
Client-sideClient-side, I just have an AngularJS app hosted on the /angular endpoint from my Flask server. The app fetches all data through the use of services. I did this through the code fragment that I found on Stack:
All front-end files are stored in *ANGULAR_STATIC_PATH* and served through Flask. It's a pretty neat setup and means that I don't have any cross-origin request issues.
I haven't bothered implementing authentication yet, which I probably should, but if I do it will follow this helpful guide which has already been broadcasted widely around AngularJS circles.
Challenges I still faceThere's a few things that I'm still unsure about that are unclear either in best-practice guides on the internet or on AngularJS' official documentation.
Most sources on the internet suggest that you have very lean controllers that don't store many functions but merely contain a baseline to call other functions. This makes sense to some extent but I am confused as to where you then store all these functions. My confusion mainly lies in how to process service data coming in from a AJAX call, after interacting with the 'promise' interface in the controller. Should the data processing (making it presentable) be done in the service? The controller? Another layer?