S
S
Splite2017-04-04 00:49:49
RESTful API
Splite, 2017-04-04 00:49:49

How to properly design Rest for one-to-many communication?

Let's say there is a board entity and another task entity that is associated with board by the board_id field.
I can implement Rest Api for task in two ways

GET /boards/{board_id}/tasks/{task_id}
GET /boards/{board_id}/tasks
POST /boards/{board_id}/tasks
PUT /boards/{board_id}/tasks/{task_id}
DELETE /boards/{board_id }/tasks/{task_id}

and the second option
GET /tasks/{task_id}
GET /boards/{board_id}/tasks
POST /boards/{board_id}/tasks
PUT /tasks/{task_id}
DELETE /tasks/{task_id}

Question regarding requests for getting, updating and deleting tasks, which of the options is correct? The id for the task is still unique for me and it makes no sense to accept also the id of the board entity, on the other hand, the first option intuitively seems more correct. What do you do in such cases and why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antoxa Zimm, 2017-04-04
@AntoXa_ZiMM

I would do in this situation without board id.
1 you work with the task entity and nothing else is needed
2 in another part of the system you will work with tasks and what will be instead of the board id?
there is a resource for working with tasks and everything else is superfluous, it seems to me.
read the link here , it may be useful and answer your question.
it seems to me that "intuitively it seems more correct" will raise questions "why this data, maybe a bug / why there is no connection between the board and the task in the database"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question