Next.js Discord

Discord Forum

REST API route logic

Answered
Maine Coon posted this in #help-forum
Open in Discord
Maine CoonOP
I would like to create a trello clone. I trying to figure out the logic. The really "bottom" route something like this:
api/workspace/:id/board/:id/list/:id/card/:id

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: 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. ?
Answered by Maine Coon
thank you
View full answer

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:


api/workspaces/:id
api/boards/:id
api/cards/:id


you should then create endpoints that allow you to retrieve the collections associated with a given id

api/workspaces/:id/boards
api/boards/:id/cards


but 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 page
Maine 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 relataions
and the solution seems logical and clean if I want to extend anything, than easy to add
Maine CoonOP
thank you
Answer