Endpoint routing how to support users/me and users/<id>
Hey, how do I support both cases?
Do i create multiple controllers?
4 Replies
for example:
/users/me/items will get the items from the current user thanks to JWT, but how at the same time can I support /users/<id>/items?
Multiple controllers with different routes?
dont need multiple controllers, but you will need multiple actions
You can do it in single action in a controller. Something like that (sorry if code will look clumsy, writing it on phone)
Would look like that in very simple example
Please don't do that. It now allows
users/meep/items
too
me
is a special route value. allow it by a special action, and have another action take {id:int}
do little to no logic in your actions, instead call shared methods that contain the actual logic there