Replies: 1 comment 7 replies
-
Creating If only What are other possibilities you can think of? 🤔 P.S: I think @mitchelvanbever and @BJvdA can give some input here. -- This discussion led me to try some other possibilites, and yesterday i could create a prototype of a router that works with this package. I'll create another discussion for that. |
Beta Was this translation helpful? Give feedback.
-
Started yesterday on an example for
next-api-decorators
and stumbled on the following issue structure wise.So for the example I wanted to create a simple CRUD example, with the following routes:
GET /api/users
(list)POST /api/users
(create)GET /api/users/:id
(read)PUT /api/users/:id
(update)DELETE /api/users/:id
(delete)Because we have 2 GET routes, this would normally be split in 2 files:
But it feels weird to split up the handler into multiple files, you would expect to have one User class that handles all the user related routes. If we wouldn’t have the list route, it could be done with one class by using an id query parameter instead of the path parameter.
If we want to tackle this problem, it could be a solution to add an optional
path
param to the decorators like:The above syntax should be possible if we use this structure (which catches both
/users
and/users/:id
):And I say “If we want” because it might just not be the right use case for
next-api-decorators
, maybe it should only be used for simple routes and not to create a complete CRUD API.Any other thoughts on this?
Beta Was this translation helpful? Give feedback.
All reactions