LetsLunch / lunch

Other
38 stars 3 forks source link

cleanup on isle `requests`! #69

Open cameron opened 10 years ago

cameron commented 10 years ago

Isolating all of your server interactions in requests is a good idea, but the file itself is more verbose than it needs to be.

If you adopt these suggestions, your requests methods get significantly shorter, especially in cases where all you're doing is mapping a method name to a url:

    'postLocation': $http.post.bind(urls.location), // <--- SO MUCH BETTER
    'getLocationDetails' : function(userId){
      return $http.get(urls.location + '/' + userId); // <--- PRETTY OKAY
    },

Stepping up to a higher philosophical plane, building URLs via string concatenation is frowned upon because it's error prone and particularly vulnerable to injection attacks (where the user submits intentionally malformed data to make a request other than what the developer intended to allow). In angular, it's slightly less dangerous because of some security policies built into the scope object, but it's something you should be aware of. Alternatives include using regex to validate URL components/args, or something like ngResource, which generates objects/methods that map to your RESTful API endpoints.

zzmp commented 10 years ago

Omkar, can you rewrite to the first philosophy? Nightmare mode: ngResource.