What is the proper way in a REST architecture to post something that is hierarchical in nature?
Let me explain.
Let's say I have a question and answer application.
Users posts questions, and each question can have many responses.
When fetching a question, with ID of 1, I would do:
GET: /question/1
When fetching the responses for question 1, I would do:
GET: /question/1/responses
(this would return a list of responses)
If I were to get a response, all by itself, I would do:
GET: /response/2
Now, How would I post a new response to question 1?
I am unsure of which approach would be correct:
Option 1:
POST: /question/1/response
Option 2:
POST /response
In Option 1, I respect the hierarchy, and operate in it. I know in the URL to which question (resource) the response will be added.
In Option 2, I need to include the Question ID in my post params. Here I would basically ignore the natural heirarchy, and treat the question ID like any other attribute on the response.
I think, the right way is option 2. Response is a stand-alone resource. In the end, Question ID is just an attribute of a response.
Well...?
Thanks