这是我目前正在做的一个玩具项目。
我的应用程序包含具有多项选择答案的问题。
问题url的格式如下,其中GET & POST映射到问题控制器上的不同操作。
GET: url.com/questions/:category/:difficulty => 'ask'
POST: url.com/questions/:category/:difficulty => 'answer'我想知道是否值得将其重新设计为RESTful风格。我知道我需要介绍答案作为一种资源,但我正在努力想出一个看起来自然的url来回答这个问题。
重新设计是否值得?您将如何着手构建urls?
发布于 2010-03-30 20:06:15
我认为你最好映射一下:
POST url.com/:category/:difficulty/questions => ask question
GET url.com/questions => list all questions
GET url.com/:category/:difficulty/questions => list questions for category and difficulty
GET url.com/questions/:id => show question
POST url.com/questions/:id => add answer
PUT url.com/questions/:id => edit question
PUT url.com/questions/:question_id/:id => edit answer with id :id
GET url.com/questions/:question_id/:id => show question with highlighted answer (like it is here on SO)如果你愿意这样做:
POST: url.com/questions/:category/:difficulty => 'answer'那么你只能有一个具有指定类别和难度的问题。
发布于 2010-03-30 19:56:31
您不必将答案视为单独的资源:您可以将答案视为问题的一个元素。事实上,我认为这会更好--一个答案没有任何价值,除非它与一个问题联系在一起。
https://stackoverflow.com/questions/2544715
复制相似问题