Question

Say I need to call /calendar/day/month/year to get my calendar for the day, but once I have the calendar, I'd like to only make a PUT request to /calendar/id. How can I accomplish this with one $resource? How can I create multiple URLs depending on the call method?

Thanks!

Was it helpful?

Solution

You can override the URL on action level:

app.factory('Calendar', function ($resource) {
  return $resource('/calendar', {}, {
    query: { 
      method: 'GET', 
      url: '/calendar/:day/:month/:year', 
      params: { 
        day: '@day', month: '@month', year: '@year' 
      } 
    },
    save: { 
      method: 'PUT', 
      url: '/calendar/:id', 
      params: { 
        id: '@id' 
      } 
    }
  });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top