1

I'm trying to make a POST request to a URL with the following format:

/questions/:questionId:/answers

I have a resource set up (notice the custom save URL):

angular.module('questions').factory('AnswersResource',
    ['$resource',
    function($resource) {
        return $resource('questions/:questionId/answers/:answerId', {
            answerId: '@_id'
        }, {
            save: {
                method: 'POST',
                url: 'questions/:questionId/answers'
            }
        });
    }
]);

With a wrapper:

angular.module('questions').factory('Answers',
    ['AnswersResource',
    function(AnswersResource) {
        return {
            save: function(answer, questionId) {
                AnswersResource.save({questionId: questionId}, answer);
            }
        }
    }
]);

When I make a call to:

Answers.save($scope.answer, '123456');

I get a POST request to the server like this (notice the appended question mark):

POST /questions/123456/answers?

This throws off the routing on my back-end. Does anyone know why this question mark is appearing?

Thanks!

3
  • Are you using Restangular? Commented Mar 20, 2014 at 21:39
  • No, I was just using regular $resource. I hadn't heard of Restangular before but now that I've checked it out I'll definitely consider it for future projects. Commented Mar 21, 2014 at 20:30
  • I wonder why you have the answerId: '@_id' bit. Commented Sep 16, 2014 at 20:21

1 Answer 1

1

Although I still don't know why the question mark was being appended, I managed to fix the problem by simply removing my custom URL. It turns out that the $save command is smart enough to know to post to: /questions/123456/answers even without specifying my own URL.

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

Comments

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.