Isolating all of your server interactions in requests is a good idea, but the file itself is more verbose than it needs to be.
Using $http.{get,post,delete} instead of $http({'method':'',..}) will save you 15 lines and increase readability
Add the baseUrl to each value in the urls object rather than adding it in each resource method (e.g., requests.getDetails) to avoid writing repetitive string concatenation
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:
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.
Isolating all of your server interactions in requests is a good idea, but the file itself is more verbose than it needs to be.
urls
object rather than adding it in each resource method (e.g.,requests.getDetails
) to avoid writing repetitive string concatenationIf 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: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.