johnhof/IceBuddy — pull request #14 by johnhof (2014-12-13 07:33:38+00:00)
Title: Added proxy to access the API from the app. Added API req logging. Added several Angular services and an API resource wrapper

@DuaneBrander

important take aways from this

* grunt-connect-proxy will now forward requests to the API (configured and launched from the gruntfile)
* by default routes returning 200 from the API will return `{}` instead of 'OK' to prevent the Angular json parser from throwing warnings
* updated header to be 70px (recommended by Gabe)
* changed background and font (recommended by Gabe)
* Replaced angular helpers file with services file containing
* Cookie - a simple cookie wrapper which get and sets (safely parses) JSON formatted cookies (eg. our session)
* Session - a service containing basic info from the session cookie, and a utility for sign in and sign out
* Added an Api.js file containing a service which returns as an `$http` instance with several `$resource` objects as properties
* Api() -> $http()
* Api.session - { create(), status(), read(), destroy() }
* Api.account - { create(), read(), destroy() }

I know `$resource` is a bit of overkill for these simple routes, but it lets you do convenient things like

```javascript
// defined in the Api service
Api.user = $resource('/user/:userId', {userId:'@id'});

// used in any module requiring the Api service
User.get({
userId:123
}, function (user, getResponseHeaders) {
perform some action
});
```

So they will be pretty useful later.

If you want to use a service in a controller at any point, I have the grunfile concat and minify the JS (disabled for now because it makes debugging a bitch) with services concatenating before any controllers. All you need to do is

```javascript
simpleApp.controller('SessionCtrl', ['$scope', 'Session', function ($scope, Session) {
Session; // now an instance of the session service
}]);
```
Final note/general warning. you can define angular modules without double specifying the requirements `simpleApp.controller('SessionCtrl', function ($scope, Session) {});` but that can cause problems when you minify since angular uses the variable names to map to services, controllers, etc. make sure you explicitly specify the string of the requirement in the array so Angular can map the requirement to the parameter when it's minified