customOperation and addRestangularMethod would not use BaseUrl in Restangular

521 Views Asked by At

I've been trying to create a custom method named 'upVote' for a resource called 'posts', the posts api url is at "/rest/users/{username}/posts" while the url for the vote action is at "/rest/posts/{postId}/vote".

I have added the following configuration:

RestangularProvider.setBaseUrl(Routing.getBaseUrl() + '/rest');
RestangularProvider.addElementTransformer('posts', false, function(post) {
     post.addRestangularMethod('upVote', 'patch', 'vote', {_token: ajaxToken}, {});
     return post;
});

But the method sends the request to the wrong url (/post/{postId}/vote) and does not use the provided baseUrl at all.

Is there a way to make the method use the configured baseUrl for it's requests, or am I doing this the wrong way?

0

There are 0 best solutions below