0

I was looking at AngularJs Resource documentation and it states that default actions for accessing API are: {'get': {method:'GET'}, 'save': {method:'POST'}, 'query': {method:'GET', isArray:true}, 'remove': {method:'DELETE'}, 'delete': {method:'DELETE'} };

This is a bit different from Rails RESTful API where we have index,show,new,create,edit,update and discard. Is there an "automatic" way to bind these two without writing the path manually? Thanks!

ps. why remove and delete, where's put for update?

1 Answer 1

1

ngResource simply uses different names for usual REST conventions. So for example:

var User = $resource('/user/:userId', {userId:'@id'});
var user = User.get({userId:123}, function() {
  // do something with user
});

In this example User.get()sends the following request GET /user/123 which Rails routing logic passes to UserController#show action.

Regarding the update method, you can simply create one yourself:

var User = $resource('/user/:id', {}, {
    update: {
      method: 'PUT'
    }

}
Sign up to request clarification or add additional context in comments.

2 Comments

See docs.angularjs.org/api/ngResource.$resource and particularly the information about 'action'.
Here's another example blog.berylliumwork.com/2012/09/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.