0

There is the following code:

angular.module('app.posts.services', []).factory('Post', ['$resource', 'API_ENDPOINT', ($resource, API_ENDPOINT) ->
    $resource(API_ENDPOINT, { id: '@id' }, {
        update: {
            method: 'PUT'
        }
    })
]).value('API_ENDPOINT', 'http://somedomainname.com/users/:user_id/posts/:id')

But for the update method I want to change the URL format: "http://somedomainname.com/posts/:id". How can I do it?

0

2 Answers 2

1

Yes, you can change the URLs of specific action methods. It's documented in the $resource documentation in the actions parameter:

url – {string} – action specific url override. The url templating is supported just like for the resource-level urls.

JavaScript

angular.module('app.posts.services', []).factory('Post', ['$resource', 'API_ENDPOINT', ($resource, API_ENDPOINT) ->
    $resource(API_ENDPOINT, { id: '@id' }, {
        update: {
            method: 'PUT',
            url: 'http://somedomainname.com/posts/:id'
        }
    })
]).value('API_ENDPOINT', 'http://somedomainname.com/users/:user_id/posts/:id')
Sign up to request clarification or add additional context in comments.

Comments

0

The angular.value or angular.constant could be used:

Providers

2 Comments

I mean I want to change url for delete method only!
Im not sure if it is valid. RESTful format it is a patter which you should not change. And $resource is a solution for that. I think you should use an "alternative solution for delete". But i think delete URL should be fixed, not your method.

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.