Design RESTful Question / Answer?

This is a toy project I'm working on now.

My application contains questions with answers to several options.

The question URL is in the following format: GETand POSTmapping various actions to the question controller.

GET:   url.com/questions/:category/:difficulty      => 'ask'
POST:  url.com/questions/:category/:difficulty      => 'answer'

I am wondering if it is worth redrawing it in RESTful style. I know that I will need to submit the answers as a resource, but I'm struggling to come up with a URL that would look natural to answer this question.

Will the redesign be worth it? How are you going to structure your urls?

+3
source share
2 answers

, , :

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'

.

+3

: . , , - , .

+2

Source: https://habr.com/ru/post/1739134/


All Articles