I'm working on a quiz system using Spring Data Rest that has the following structure:
1 Quiz contains many Questions
1 Question contains many Answers
We want to represent this with the following URL structure:
GET /quiz-service/quizzes/1/questions/1/answers - Gets all the answers belonging to question 1 within quiz 1.
POST /quiz-service/quizzes/1/questions/1/answers - Adds an answer to question 1 within quiz 1.
POST /quiz-service/quizzes/1/questions - Adds a question to quiz 1.
At the moment, when we try and POST to the above, we get an HTTP 40-something code.
All IDs in the above URLs are unique. The following, with 2 different quizzes referring to the same question, would cause a problem:
/quiz-service/quizzes/1/questions/1 - would be HTTP OK
/quiz-service/quizzes/2/questions/1 - would result with HTTP NOT FOUND given the above.
We have a repository interface for all 3, quizzes, questions and answers.
As per this post and others we've seen, we know that you can POST to /quiz-service/questions and either include a link to the quiz, or make a 2nd request to the quiz endpoint adding the question. Despite this, is there any way at all that we can do the above?
Thanks in advance