Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

Come on...really?
No REST fanatic wants to rip me a new one for my misuse of REST?
nobody has any opinion at all?

its wide open for anybody to just tear me apart...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900