REST API route logic
Answered
Maine Coon posted this in #help-forum
Maine CoonOP
I would like to create a trello clone. I trying to figure out the logic. The really "bottom" route something like this:
It seems a bit complex for URI, so I am not sure what would be the good approach here, how should I organize az API routes.
The model structure:
The reason of chain, I have to get
Can you give me advice about the structure, route etc. ?
api/workspace/:id/board/:id/list/:id/card/:idIt seems a bit complex for URI, so I am not sure what would be the good approach here, how should I organize az API routes.
The model structure:
workspace has relation to board, board has relation to list, list has relation to card.The reason of chain, I have to get
worskapceId if I am at board route because I have to set relation between board and worskapce model Can you give me advice about the structure, route etc. ?
7 Replies
Australian Freshwater Crocodile
If you want to remain restful, consider if a card belongs to a list, and a list to a board. If a list can change boards, or a card can change lists, you should not make it a nested collection. So you would have the different collections available as:
you should then create endpoints that allow you to retrieve the collections associated with a given id
but it wont be possible to keep digging more than that.
api/workspaces/:id
api/boards/:id
api/cards/:idyou should then create endpoints that allow you to retrieve the collections associated with a given id
api/workspaces/:id/boards
api/boards/:id/cardsbut it wont be possible to keep digging more than that.
api/workspace/:id/boards/:id // Not valid, if you want to access the board, use the boards endpoint
api/board/:id // Correct!for UI pages routing, consider using intercepting routes.
/boards // shows the boards
/boards/[id] // shows you a specific board
/card/[id] // shows you a card as a stand alone page
/boards/(..)card/[id] // shows you card as a modal, this intercepts the route that goes to the standalone page when the user is on the boards pageMaine CoonOP
So i should combine the board route with workspace, the list with board and the card with list
but I do not need to do many nesting routes
it seems logical, a little bit not so direct, but the model 'chain' stucture needs to solve in a not so generic way like
api/workspaces/:id and need to create separate routes for workspace-board, board-list, list-card relataionsand the solution seems logical and clean if I want to extend anything, than easy to add
Maine CoonOP
thank you
Answer