这是我目前正在做的一个玩具项目。
我的应用包含多项选择题。
问题 url 采用以下格式,GET
和 POST
映射到问题 Controller 上的不同操作。
GET: url.com/questions/:category/:difficulty => 'ask'
POST: url.com/questions/:category/:difficulty => 'answer'
我想知道是否值得将其重新设计为 RESTful 风格。我知道我需要将答案作为资源引入,但我正在努力想一个看起来很自然的 url 来回答这个问题。
重新设计是否值得?您将如何构建 URL?
最佳答案
我认为如果你映射会更好:
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'
那么你只能有一个指定类别和难度的问题。
关于ruby-on-rails - RESTful 问答设计?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2544715/